[ python-Bugs-1576241 ] functools.wraps fails on builtins

SourceForge.net noreply at sourceforge.net
Fri Oct 27 18:07:52 CEST 2006


Bugs item #1576241, was opened at 2006-10-13 08:24
Message generated for change (Comment added) made by ncoghlan
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1576241&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: kajiuma (kajiuma)
Assigned to: Nick Coghlan (ncoghlan)
Summary: functools.wraps fails on builtins

Initial Comment:
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.


----------------------------------------------------------------------

>Comment By: Nick Coghlan (ncoghlan)
Date: 2006-10-28 02:07

Message:
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.

----------------------------------------------------------------------

Comment By: A.M. Kuchling (akuchling)
Date: 2006-10-27 05:18

Message:
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.)


----------------------------------------------------------------------

Comment By: kajiuma (kajiuma)
Date: 2006-10-13 08:33

Message:
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


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1576241&group_id=5470


More information about the Python-bugs-list mailing list