Created
September 10, 2019 20:53
-
-
Save wchargin/422669b007919f55e8a67efec6dfc95c to your computer and use it in GitHub Desktop.
`@functools.wraps(functools.partial(…))` decorator broken in Python 2.7.16
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import functools | |
print(sys.version_info) | |
partial = functools.partial(id, 1) | |
@functools.wraps(partial) | |
def foo(): | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python functools_wraps_partial.py | |
sys.version_info(major=2, minor=7, micro=16, releaselevel='final', serial=0) | |
Traceback (most recent call last): | |
File "functools_wraps_partial.py", line 8, in <module> | |
@functools.wraps(partial) | |
File "/usr/lib/python2.7/functools.py", line 33, in update_wrapper | |
setattr(wrapper, attr, getattr(wrapped, attr)) | |
AttributeError: 'functools.partial' object has no attribute '__module__' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One-liner:
works in Python 3 but fails in Python 2.