Skip to content

Add __name__ to _Wrapped in functools #9835

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

Merged
merged 4 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions stdlib/functools.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ WRAPPER_UPDATES: tuple[Literal["__dict__"]]
class _Wrapped(Generic[_PWrapped, _RWrapped, _PWrapper, _RWapper]):
__wrapped__: Callable[_PWrapped, _RWrapped]
def __call__(self, *args: _PWrapper.args, **kwargs: _PWrapper.kwargs) -> _RWapper: ...
# as with ``Callable``, we'll assume that these attributes exist
__name__: str
__qualname__: str

class _Wrapper(Generic[_PWrapped, _RWrapped]):
def __call__(self, f: Callable[_PWrapper, _RWapper]) -> _Wrapped[_PWrapped, _RWrapped, _PWrapper, _RWapper]: ...
Expand Down
23 changes: 22 additions & 1 deletion test_cases/stdlib/check_functools.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
from __future__ import annotations

import sys
from functools import wraps
from typing import Callable, TypeVar
from typing_extensions import ParamSpec, assert_type

P = ParamSpec("P")
T_co = TypeVar("T_co", covariant=True)


def my_decorator(func: Callable[P, T_co]) -> Callable[P, T_co]:
@wraps(func)
def wrapper(*args: P.args, **kwargs: P.kwargs) -> T_co:
print(args)
return func(*args, **kwargs)

# verify that the wrapped function has all these attributes
wrapper.__annotations__ = func.__annotations__
wrapper.__doc__ = func.__doc__
wrapper.__module__ = func.__module__
wrapper.__name__ = func.__name__
wrapper.__qualname__ = func.__qualname__
return wrapper


if sys.version_info >= (3, 8):
from functools import cached_property
from typing_extensions import assert_type

class A:
def __init__(self, x: int):
Expand Down