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.

classification
Title: functools.wraps fails on builtins
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: akuchling Nosy List: akuchling, kajiuma, ncoghlan
Priority: normal Keywords:

Created on 2006-10-12 22:24 by kajiuma, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg30229 - (view) Author: kajiuma (kajiuma) Date: 2006-10-12 22:24
functools.wraps assumes that the wrapped function 
has a __dict__ attribute, which is not true for 
builtins.

The attached patch provides an empty dictionaries 
for functions that do not have the required 
attributes. This will cause programs expecting an 
AttributeError (if there are any) to fail.
msg30230 - (view) Author: kajiuma (kajiuma) Date: 2006-10-12 22:33
Logged In: YES 
user_id=1619773

Looks like lynx cannot send files.
The patch changed: getattr(wrapped, attr)
to: getattr(wrapped, attr, {})
At then end of line 35 of Lib/functools.py
msg30231 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2006-10-26 19:18
Logged In: YES 
user_id=11375

The change seems reasonable, but arguably this is an API
change because of the AttributeError no longer being raised.
 Nick, do you want to decide whether to make this change or
not?  (I can make the edit and add a test if you agree to
apply this change.)
msg30232 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2006-10-27 16:07
Logged In: YES 
user_id=1038590

I was mainly considering the decorator use case when I wrote
the function, so the idea of a wrapped function without a
dict attribute didn't occur to me (obviously!).

So definitely fix it on the trunk, and I'd say backport it
to 2.5 as well. My reasoning regarding the latter is that
the example code in the documentation for functools.wraps is
actually buggy with the current behaviour. With this bug
fixed, the documentation example will work as intended.
msg30233 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2006-10-27 16:42
Logged In: YES 
user_id=11375

Committed to trunk (rev.52476) and 25-maint (rev. 52477). 
thanks for your patch!
History
Date User Action Args
2022-04-11 14:56:20adminsetgithub: 44122
2006-10-12 22:24:20kajiumacreate