Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

functools.wraps fails on builtins #44122

Closed
kajiuma mannequin opened this issue Oct 12, 2006 · 5 comments
Closed

functools.wraps fails on builtins #44122

kajiuma mannequin opened this issue Oct 12, 2006 · 5 comments
Assignees
Labels
stdlib Python modules in the Lib dir

Comments

@kajiuma
Copy link
Mannequin

kajiuma mannequin commented Oct 12, 2006

BPO 1576241
Nosy @akuchling, @ncoghlan

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/akuchling'
closed_at = <Date 2006-10-27.16:42:29.000>
created_at = <Date 2006-10-12.22:24:20.000>
labels = ['library']
title = 'functools.wraps fails on builtins'
updated_at = <Date 2006-10-27.16:42:29.000>
user = 'https://bugs.python.org/kajiuma'

bugs.python.org fields:

activity = <Date 2006-10-27.16:42:29.000>
actor = 'akuchling'
assignee = 'akuchling'
closed = True
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2006-10-12.22:24:20.000>
creator = 'kajiuma'
dependencies = []
files = []
hgrepos = []
issue_num = 1576241
keywords = []
message_count = 5.0
messages = ['30229', '30230', '30231', '30232', '30233']
nosy_count = 3.0
nosy_names = ['akuchling', 'ncoghlan', 'kajiuma']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue1576241'
versions = ['Python 2.5']

@kajiuma
Copy link
Mannequin Author

kajiuma mannequin commented Oct 12, 2006

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.

@kajiuma kajiuma mannequin closed this as completed Oct 12, 2006
@kajiuma kajiuma mannequin assigned akuchling Oct 12, 2006
@kajiuma kajiuma mannequin added the stdlib Python modules in the Lib dir label Oct 12, 2006
@kajiuma kajiuma mannequin closed this as completed Oct 12, 2006
@kajiuma kajiuma mannequin assigned akuchling Oct 12, 2006
@kajiuma kajiuma mannequin added the stdlib Python modules in the Lib dir label Oct 12, 2006
@kajiuma
Copy link
Mannequin Author

kajiuma mannequin commented Oct 12, 2006

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

@akuchling
Copy link
Member

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

@ncoghlan
Copy link
Contributor

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.

@akuchling
Copy link
Member

Logged In: YES
user_id=11375

Committed to trunk (rev.52476) and 25-maint (rev. 52477).
thanks for your patch!

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

2 participants