Skip to content

Instantly share code, notes, and snippets.

@wchargin
Created September 10, 2019 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wchargin/422669b007919f55e8a67efec6dfc95c to your computer and use it in GitHub Desktop.
Save wchargin/422669b007919f55e8a67efec6dfc95c to your computer and use it in GitHub Desktop.
`@functools.wraps(functools.partial(…))` decorator broken in Python 2.7.16
import sys
import functools
print(sys.version_info)
partial = functools.partial(id, 1)
@functools.wraps(partial)
def foo():
pass
$ 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__'
@wchargin
Copy link
Author

One-liner:

python -c 'import functools as ft; ft.wraps(ft.partial(id))(lambda: 0)'

works in Python 3 but fails in Python 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment