-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Make collections.abcs more consistent with runtime implementation #10816
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 all commits
78a77de
0fd644f
049a270
ab4613b
0d7868f
c7fead5
92782a2
cab10a8
255b6f0
bf8700f
a2ce3b2
ab12c5e
fae5bed
e1673b4
2cd7e8f
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 |
|---|---|---|
|
|
@@ -12,7 +12,6 @@ from re import Match as Match, Pattern as Pattern | |
| from types import ( | ||
| BuiltinFunctionType, | ||
| CodeType, | ||
| FrameType, | ||
| FunctionType, | ||
| MethodDescriptorType, | ||
| MethodType, | ||
|
|
@@ -473,7 +472,8 @@ _YieldT_co = TypeVar("_YieldT_co", covariant=True) | |
| _SendT_contra = TypeVar("_SendT_contra", contravariant=True, default=None) | ||
| _ReturnT_co = TypeVar("_ReturnT_co", covariant=True, default=None) | ||
|
|
||
| class Generator(Iterator[_YieldT_co], Generic[_YieldT_co, _SendT_contra, _ReturnT_co]): | ||
| @runtime_checkable | ||
| class Generator(Iterator[_YieldT_co], Protocol[_YieldT_co, _SendT_contra, _ReturnT_co]): | ||
| def __next__(self) -> _YieldT_co: ... | ||
| @abstractmethod | ||
| def send(self, value: _SendT_contra, /) -> _YieldT_co: ... | ||
|
|
@@ -491,14 +491,6 @@ class Generator(Iterator[_YieldT_co], Generic[_YieldT_co, _SendT_contra, _Return | |
| def close(self) -> None: ... | ||
|
|
||
| def __iter__(self) -> Generator[_YieldT_co, _SendT_contra, _ReturnT_co]: ... | ||
|
Contributor
Author
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. I'm unsure as to whether or not this should be -> Self the runtime has it as that in Iterator
Contributor
Author
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. Upon further consideration, not implementing it as returning Self is probably a bug so I'll change it in (Async)Iterator even
Member
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.
With
Member
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. I suspect removing this method is causing the mypy-primer fallout. Let's add it back. |
||
| @property | ||
| def gi_code(self) -> CodeType: ... | ||
| @property | ||
| def gi_frame(self) -> FrameType: ... | ||
| @property | ||
| def gi_running(self) -> bool: ... | ||
| @property | ||
| def gi_yieldfrom(self) -> Generator[Any, Any, Any] | None: ... | ||
|
|
||
| # NOTE: Prior to Python 3.13 these aliases are lacking the second _ExitT_co parameter | ||
| if sys.version_info >= (3, 13): | ||
|
|
@@ -524,14 +516,7 @@ _ReturnT_co_nd = TypeVar("_ReturnT_co_nd", covariant=True) | |
| class Coroutine(Awaitable[_ReturnT_co_nd], Generic[_YieldT_co, _SendT_contra_nd, _ReturnT_co_nd]): | ||
| __name__: str | ||
| __qualname__: str | ||
| @property | ||
| def cr_await(self) -> Any | None: ... | ||
| @property | ||
| def cr_code(self) -> CodeType: ... | ||
| @property | ||
| def cr_frame(self) -> FrameType | None: ... | ||
| @property | ||
| def cr_running(self) -> bool: ... | ||
|
|
||
| @abstractmethod | ||
| def send(self, value: _SendT_contra_nd, /) -> _YieldT_co: ... | ||
| @overload | ||
|
|
@@ -566,7 +551,8 @@ class AsyncIterator(AsyncIterable[_T_co], Protocol[_T_co]): | |
| def __anext__(self) -> Awaitable[_T_co]: ... | ||
| def __aiter__(self) -> AsyncIterator[_T_co]: ... | ||
|
|
||
| class AsyncGenerator(AsyncIterator[_YieldT_co], Generic[_YieldT_co, _SendT_contra]): | ||
| @runtime_checkable | ||
| class AsyncGenerator(AsyncIterator[_YieldT_co], Protocol[_YieldT_co, _SendT_contra]): | ||
| def __anext__(self) -> Coroutine[Any, Any, _YieldT_co]: ... | ||
| @abstractmethod | ||
| def asend(self, value: _SendT_contra, /) -> Coroutine[Any, Any, _YieldT_co]: ... | ||
|
|
@@ -581,14 +567,6 @@ class AsyncGenerator(AsyncIterator[_YieldT_co], Generic[_YieldT_co, _SendT_contr | |
| self, typ: BaseException, val: None = None, tb: TracebackType | None = None, / | ||
| ) -> Coroutine[Any, Any, _YieldT_co]: ... | ||
| def aclose(self) -> Coroutine[Any, Any, None]: ... | ||
| @property | ||
| def ag_await(self) -> Any: ... | ||
| @property | ||
| def ag_code(self) -> CodeType: ... | ||
| @property | ||
| def ag_frame(self) -> FrameType: ... | ||
| @property | ||
| def ag_running(self) -> bool: ... | ||
|
|
||
| @runtime_checkable | ||
| class Container(Protocol[_T_co]): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be interested what happens if we just change types.pyi, but remove the
typingbase classes to better match runtime.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure what you're proposing, wouldn't that just crash mypy because typing.Generator wouldn't exist?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant just using
class GeneratorType:here (and adding the methods), not deletingtyping.Generator.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typing.Generator hasn't been deleted it's just a protocol now