-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Improve abc module and builtin function decorators (with ParamSpec) #5682
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
Changes from 3 commits
f03d008
f40490b
16b9d8a
409aaa1
df2f05f
02ab1b6
704dc43
8d73ca4
e0f6ee1
ddfd634
06a0ce0
aa5c5df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ from _typeshed import ( | |
SupportsWrite, | ||
) | ||
from ast import AST, mod | ||
from collections.abc import Callable | ||
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper | ||
from types import CodeType, TracebackType | ||
from typing import ( | ||
|
@@ -26,7 +27,6 @@ from typing import ( | |
AsyncIterator, | ||
BinaryIO, | ||
ByteString, | ||
Callable, | ||
Dict, | ||
FrozenSet, | ||
Generic, | ||
|
@@ -80,6 +80,7 @@ _T4 = TypeVar("_T4") | |
_T5 = TypeVar("_T5") | ||
_TT = TypeVar("_TT", bound="type") | ||
_TBE = TypeVar("_TBE", bound="BaseException") | ||
_FuncT = TypeVar("_FuncT", bound=Callable[..., Any]) | ||
|
||
class object: | ||
__doc__: Optional[str] | ||
|
@@ -109,19 +110,19 @@ class object: | |
def __dir__(self) -> Iterable[str]: ... | ||
def __init_subclass__(cls) -> None: ... | ||
|
||
class staticmethod(object): # Special, only valid as a decorator. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: These comments should be deleted. They seem misleading and mypy-specific to me. |
||
__func__: Callable[..., Any] | ||
class staticmethod(Generic[_FuncT]): # Special, only valid as a decorator. | ||
__func__: _FuncT | ||
__isabstractmethod__: bool | ||
def __init__(self, f: Callable[..., Any]) -> None: ... | ||
def __init__(self, f: _FuncT) -> None: ... | ||
def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... | ||
def __get__(self, obj: _T, type: Optional[Type[_T]] = ...) -> Callable[..., Any]: ... | ||
def __get__(self, obj: _T, type: Type[_T] | None = ...) -> _FuncT: ... | ||
|
||
class classmethod(object): # Special, only valid as a decorator. | ||
__func__: Callable[..., Any] | ||
class classmethod(Generic[_FuncT]): # Special, only valid as a decorator. | ||
__func__: _FuncT | ||
__isabstractmethod__: bool | ||
def __init__(self, f: Callable[..., Any]) -> None: ... | ||
def __init__(self, f: _FuncT) -> None: ... | ||
def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... | ||
def __get__(self, obj: _T, type: Optional[Type[_T]] = ...) -> Callable[..., Any]: ... | ||
def __get__(self, obj: _T, type: Type[_T] | None = ...) -> _FuncT: ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem right, because the callable returned from >>> class Foo:
... @classmethod
... def bar(cls):
... print("Bar runs:", cls)
...
>>> Foo.bar()
Bar runs: <class '__main__.Foo'>
>>> Foo.__dict__['bar'].__func__(Foo)
Bar runs: <class '__main__.Foo'> Here >>> Foo.bar == Foo.__dict__['bar'].__get__(Foo(), None)
True
>>> Foo.bar
<bound method Foo.bar of <class '__main__.Foo'>> There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another problem: I think it calls There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. I tried to express this using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It appears to be a technicality that doesn't really occur in practice: "Python’s own |
||
|
||
class type(object): | ||
__base__: type | ||
|
Uh oh!
There was an error while loading. Please reload this page.