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

Chaining @wraps with non-modifying then modifying signatures leads to erroneous __wrapped__ flag been kept. #66

Closed
smarie opened this issue Mar 17, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@smarie
Copy link
Owner

smarie commented Mar 17, 2021

def a(foo):
    return foo + 1

assert a(1) == 2

# create a first wrapper that is signature-preserving

@wraps(a)
def wrapper(foo):
    return a(foo) - 1

assert wrapper(1) == 1

# the __wrapped__ attr is here:
assert wrapper.__wrapped__ is a

# create a second wrapper that is not signature-preserving

@wraps(wrapper, append_args="bar")
def second_wrapper(foo, bar):
    return wrapper(foo) + bar

assert second_wrapper(1, -1) == 0

with pytest.raises(AttributeError):
    second_wrapper.__wrapped__   # <---- does not raise ! 
@smarie smarie added the bug Something isn't working label Mar 17, 2021
@smarie smarie closed this as completed in 95c63d0 Mar 17, 2021
lucaswiman added a commit to lucaswiman/python-makefun that referenced this issue Jun 25, 2022
I am not sure the fix for smarie#66 was correct given that __wrapped__ is used by the
typing module in get_type_hints, and setting __signature__ seems to fix all other tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant