Update a wrapper function to look like the wrapped function wrapper is the function to be updated wrapped is the original function assigned is a tuple naming the attributes assigned directly from the wrapped function to the wrapper function (defaults to functools.
(wrapper,
wrapped,
assigned = WRAPPER_ASSIGNMENTS,
updated = WRAPPER_UPDATES)
| 33 | '__annotate__', '__type_params__') |
| 34 | WRAPPER_UPDATES = ('__dict__',) |
| 35 | def update_wrapper(wrapper, |
| 36 | wrapped, |
| 37 | assigned = WRAPPER_ASSIGNMENTS, |
| 38 | updated = WRAPPER_UPDATES): |
| 39 | """Update a wrapper function to look like the wrapped function |
| 40 | |
| 41 | wrapper is the function to be updated |
| 42 | wrapped is the original function |
| 43 | assigned is a tuple naming the attributes assigned directly |
| 44 | from the wrapped function to the wrapper function (defaults to |
| 45 | functools.WRAPPER_ASSIGNMENTS) |
| 46 | updated is a tuple naming the attributes of the wrapper that |
| 47 | are updated with the corresponding attribute from the wrapped |
| 48 | function (defaults to functools.WRAPPER_UPDATES) |
| 49 | """ |
| 50 | for attr in assigned: |
| 51 | try: |
| 52 | value = getattr(wrapped, attr) |
| 53 | except AttributeError: |
| 54 | pass |
| 55 | else: |
| 56 | setattr(wrapper, attr, value) |
| 57 | for attr in updated: |
| 58 | getattr(wrapper, attr).update(getattr(wrapped, attr, {})) |
| 59 | # Issue #17482: set __wrapped__ last so we don't inadvertently copy it |
| 60 | # from the wrapped function when updating __dict__ |
| 61 | wrapper.__wrapped__ = wrapped |
| 62 | # Return the wrapper so this can be used as a decorator via partial() |
| 63 | return wrapper |
| 64 | |
| 65 | def wraps(wrapped, |
| 66 | assigned = WRAPPER_ASSIGNMENTS, |
no test coverage detected
searching dependent graphs…