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

Improve decorator #13703

Merged
merged 2 commits into from
Mar 23, 2025
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
5 changes: 0 additions & 5 deletions stubs/decorator/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
decorator.ContextManager.__init__
decorator.FunctionMaker.args
decorator.FunctionMaker.kwonlyargs
decorator.FunctionMaker.kwonlydefaults
decorator.FunctionMaker.varargs
decorator.FunctionMaker.varkw
decorator.decorate
decorator.decorator
decorator.get_init
decorator.EMPTY
16 changes: 8 additions & 8 deletions stubs/decorator/decorator.pyi
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import inspect
from builtins import dict as _dict # alias to avoid conflicts with attribute name
from collections.abc import Callable, Iterator
from collections.abc import Callable, Generator, Iterator
from contextlib import _GeneratorContextManager
from inspect import Signature, getfullargspec as getfullargspec, iscoroutinefunction as iscoroutinefunction
from re import Pattern
from typing import Any, Literal, TypeVar
from typing import Any, Final, Literal, TypeVar
from typing_extensions import ParamSpec

_C = TypeVar("_C", bound=Callable[..., Any])
_Func = TypeVar("_Func", bound=Callable[..., Any])
_T = TypeVar("_T")
_P = ParamSpec("_P")

def get_init(cls: type) -> None: ...

DEF: Pattern[str]
POS: Literal[inspect._ParameterKind.POSITIONAL_OR_KEYWORD]
DEF: Final[Pattern[str]]
POS: Final[Literal[inspect._ParameterKind.POSITIONAL_OR_KEYWORD]]
EMPTY: Final[type[inspect._empty]]

class FunctionMaker:
args: list[str]
Expand Down Expand Up @@ -59,13 +58,14 @@ class FunctionMaker:
) -> Callable[..., Any]: ...

def fix(args: tuple[Any, ...], kwargs: dict[str, Any], sig: Signature) -> tuple[tuple[Any, ...], dict[str, Any]]: ...
def decorate(func: _Func, caller: Callable[..., Any], extras: Any = ...) -> _Func: ...
def decorate(func: _Func, caller: Callable[..., Any], extras: tuple[Any, ...] = ..., kwsyntax: bool = False) -> _Func: ...
def decoratorx(caller: Callable[..., Any]) -> Callable[..., Any]: ...
def decorator(
caller: Callable[..., Any], _func: Callable[..., Any] | None = ...
caller: Callable[..., Any], _func: Callable[..., Any] | None = None, kwsyntax: bool = False
) -> Callable[[Callable[..., Any]], Callable[..., Any]]: ...

class ContextManager(_GeneratorContextManager[_T]):
def __init__(self, g: Callable[..., Generator[_T]], *a: Any, **k: Any) -> None: ...
def __call__(self, func: _C) -> _C: ...

def contextmanager(func: Callable[_P, Iterator[_T]]) -> Callable[_P, ContextManager[_T]]: ...
Expand Down