Skip to content

Commit 95faa1a

Browse files
authored
Add tests to functools.wraps (#12173)
These tests demonstrate the issue described in #10653.
1 parent 8ddd510 commit 95faa1a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

stdlib/@tests/test_cases/check_functools.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,37 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> T_co:
2323
return wrapper
2424

2525

26+
def check_wraps_function() -> None:
27+
def wrapped(x: int) -> None: ...
28+
@wraps(wrapped)
29+
def identical_wrapper(x: int) -> None: ...
30+
@wraps(wrapped)
31+
def other_signature_wrapper(x: str, y: float) -> None: ...
32+
33+
identical_wrapper(3)
34+
other_signature_wrapper("parrot", 42.0)
35+
36+
37+
def check_wraps_method() -> None:
38+
class Wrapped:
39+
def wrapped(self, x: int) -> None: ...
40+
@wraps(wrapped)
41+
def wrapper(self, x: int) -> None: ...
42+
43+
class Wrapper: # pyright: ignore[reportUnusedClass]
44+
@wraps(Wrapped.wrapped)
45+
def method(self, x: int) -> None: ...
46+
47+
@wraps(Wrapped.wrapped)
48+
def func_wrapper(x: int) -> None: ...
49+
50+
# TODO: The following should work, but currently don't.
51+
# https://github.com/python/typeshed/issues/10653
52+
# Wrapped().wrapper(3)
53+
# Wrapper().method(3)
54+
func_wrapper(3)
55+
56+
2657
class A:
2758
def __init__(self, x: int):
2859
self.x = x

0 commit comments

Comments
 (0)