From 95faa1ae24fdbc34e4668e94a7de38737e628f22 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sat, 22 Jun 2024 16:17:09 +0200 Subject: [PATCH] Add tests to functools.wraps (#12173) These tests demonstrate the issue described in #10653. --- stdlib/@tests/test_cases/check_functools.py | 31 +++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/stdlib/@tests/test_cases/check_functools.py b/stdlib/@tests/test_cases/check_functools.py index dca572683..47b6bb77c 100644 --- a/stdlib/@tests/test_cases/check_functools.py +++ b/stdlib/@tests/test_cases/check_functools.py @@ -23,6 +23,37 @@ def my_decorator(func: Callable[P, T_co]) -> Callable[P, T_co]: return wrapper +def check_wraps_function() -> None: + def wrapped(x: int) -> None: ... + @wraps(wrapped) + def identical_wrapper(x: int) -> None: ... + @wraps(wrapped) + def other_signature_wrapper(x: str, y: float) -> None: ... + + identical_wrapper(3) + other_signature_wrapper("parrot", 42.0) + + +def check_wraps_method() -> None: + class Wrapped: + def wrapped(self, x: int) -> None: ... + @wraps(wrapped) + def wrapper(self, x: int) -> None: ... + + class Wrapper: # pyright: ignore[reportUnusedClass] + @wraps(Wrapped.wrapped) + def method(self, x: int) -> None: ... + + @wraps(Wrapped.wrapped) + def func_wrapper(x: int) -> None: ... + + # TODO: The following should work, but currently don't. + # https://github.com/python/typeshed/issues/10653 + # Wrapped().wrapper(3) + # Wrapper().method(3) + func_wrapper(3) + + class A: def __init__(self, x: int): self.x = x