Skip to content

Commit

Permalink
Add tests to functools.wraps (#12173)
Browse files Browse the repository at this point in the history
These tests demonstrate the issue described in #10653.
  • Loading branch information
srittau authored Jun 22, 2024
1 parent 8ddd510 commit 95faa1a
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions stdlib/@tests/test_cases/check_functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,37 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> 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
Expand Down

0 comments on commit 95faa1a

Please sign in to comment.