This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients Antoine d'Otreppe, benjamin.peterson, ncoghlan
Date 2008-07-27.18:12:06
SpamBayes Score 8.151336e-05
Marked as misclassified No
Message-id <1217182328.89.0.102404821949.issue3445@psf.upfronthosting.co.za>
In-reply-to
Content
The problem actually has to do with trying to use update_wrapper on a
method instead of a function - bound and unbound methods don't have all
the same attributes that actual functions do.

>>> import functools
>>> functools.WRAPPER_ASSIGNMENTS
('__module__', '__name__', '__doc__')
>>> functools.WRAPPER_UPDATES
('__dict__',)
>>> def f(): pass
...
>>> class C:
...   def m(): pass
...
>>> set(dir(f)) - set(dir(C.m))
set(['func_closure', 'func_dict', '__module__', 'func_name',
'func_defaults', '__dict__', '__name__', 'func_code', 'func_doc',
'func_globals'])

Is an exception the right response when encountering a missing
attribute? Given that the error can be explicitly silenced by writing
"functools.update_wrapper(g, str.split,
set(functools.WRAPPER_ASSIGNMENTS) & set(dir(str.split)))", I'm inclined
to think the current behaviour is the correct option.

Since this is an issue that doesn't come up with the main intended use
case for update_wrapper (writing decorators), and since it can be
handled easily by limiting the set of attributes copied to those the
object actually has, I'm converting this tracker item to an enhancement
request asking for a shorter way of spelling "ignore missing attributes"
(e.g. a keyword-only flag).
History
Date User Action Args
2008-07-27 18:12:09ncoghlansetrecipients: + ncoghlan, benjamin.peterson, Antoine d'Otreppe
2008-07-27 18:12:08ncoghlansetmessageid: <1217182328.89.0.102404821949.issue3445@psf.upfronthosting.co.za>
2008-07-27 18:12:07ncoghlanlinkissue3445 messages
2008-07-27 18:12:06ncoghlancreate