Skip to content

Commit

Permalink
Remove update_wrapper from public interface
Browse files Browse the repository at this point in the history
  • Loading branch information
immerrr committed Nov 19, 2019
1 parent 273df6c commit e2b5dac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
9 changes: 0 additions & 9 deletions documentation/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,6 @@ functions and methods is the stdlib :mod:`py3:inspect` module.
aliased to :class:`py3:object`.)


.. function:: update_wrapper(wrapper, wrapped, assigned=functools.WRAPPER_ASSIGNMENTS, updated=functools.WRAPPER_UPDATES)

This does exactly the same what the :func:`py3:functools.update_wrapper`
function does on Python versions after 3.2. It sets the ``__wrapped__``
attribute on ``wrapper`` object and it doesn't raise an error if any of the
attributes mentioned in ``assigned`` and ``updated`` are missing on
``wrapped`` object.


.. decorator:: wraps(wrapped, assigned=functools.WRAPPER_ASSIGNMENTS, updated=functools.WRAPPER_UPDATES)

This does exactly the same what the :func:`py3:functools.wraps` decorator
Expand Down
17 changes: 10 additions & 7 deletions six.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,9 +808,14 @@ def print_(*args, **kwargs):
_add_doc(reraise, """Reraise an exception.""")

if sys.version_info[0:2] < (3, 4):
def update_wrapper(wrapper, wrapped,
assigned=functools.WRAPPER_ASSIGNMENTS,
updated=functools.WRAPPER_UPDATES):
# This does exactly the same what the :func:`py3:functools.update_wrapper`
# function does on Python versions after 3.2. It sets the ``__wrapped__``
# attribute on ``wrapper`` object and it doesn't raise an error if any of
# the attributes mentioned in ``assigned`` and ``updated`` are missing on
# ``wrapped`` object.
def _update_wrapper(wrapper, wrapped,
assigned=functools.WRAPPER_ASSIGNMENTS,
updated=functools.WRAPPER_UPDATES):
for attr in assigned:
try:
value = getattr(wrapped, attr)
Expand All @@ -822,16 +827,15 @@ def update_wrapper(wrapper, wrapped,
getattr(wrapper, attr).update(getattr(wrapped, attr, {}))
wrapper.__wrapped__ = wrapped
return wrapper
update_wrapper.__doc__ = functools.update_wrapper.__doc__
_update_wrapper.__doc__ = functools.update_wrapper.__doc__

def wraps(wrapped, assigned=functools.WRAPPER_ASSIGNMENTS,
updated=functools.WRAPPER_UPDATES):
return functools.partial(update_wrapper, wrapped=wrapped,
return functools.partial(_update_wrapper, wrapped=wrapped,
assigned=assigned, updated=updated)
wraps.__doc__ = functools.wraps.__doc__

else:
update_wrapper = functools.update_wrapper
wraps = functools.wraps


Expand Down Expand Up @@ -935,7 +939,6 @@ def ensure_text(s, encoding='utf-8', errors='strict'):
raise TypeError("not expecting type '%s'" % type(s))



def python_2_unicode_compatible(klass):
"""
A class decorator that defines __unicode__ and __str__ methods under Python 2.
Expand Down

0 comments on commit e2b5dac

Please sign in to comment.