Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.1k
stdlib: add __slots__#14611
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
Uh oh!
There was an error while loading. Please reload this page.
stdlib: add __slots__ #14611
Changes from all commits
709de3a2beeb66d3e85419173e2bfab7a7d15cdab148228d6e841410c285ca773d6f1fFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -6,21 +6,26 @@ from typing import Any | ||
| __all__ = ("BaseProtocol", "Protocol", "DatagramProtocol", "SubprocessProtocol", "BufferedProtocol") | ||
| class BaseProtocol: | ||
| __slots__ = () | ||
| def connection_made(self, transport: transports.BaseTransport) -> None: ... | ||
| def connection_lost(self, exc: Exception | None) -> None: ... | ||
| def pause_writing(self) -> None: ... | ||
| def resume_writing(self) -> None: ... | ||
| class Protocol(BaseProtocol): | ||
| # Need annotation or mypy will complain about 'Cannot determine type of "__slots__" in base class' | ||
| __slots__: tuple[()] = () | ||
| def data_received(self, data: bytes) -> None: ... | ||
| def eof_received(self) -> bool | None: ... | ||
| class BufferedProtocol(BaseProtocol): | ||
| __slots__ = () | ||
| def get_buffer(self, sizehint: int) -> ReadableBuffer: ... | ||
| def buffer_updated(self, nbytes: int) -> None: ... | ||
| def eof_received(self) -> bool | None: ... | ||
| class DatagramProtocol(BaseProtocol): | ||
| __slots__ = () | ||
| def connection_made(self, transport: transports.DatagramTransport) -> None: ... # type: ignore[override] | ||
| # addr can be a tuple[int, int] for some unusual protocols like socket.AF_NETLINK. | ||
| # Use tuple[str | Any, int] to not cause typechecking issues on most usual cases. | ||
| @@ -30,6 +35,7 @@ class DatagramProtocol(BaseProtocol): | ||
| def error_received(self, exc: Exception) -> None: ... | ||
| class SubprocessProtocol(BaseProtocol): | ||
| __slots__: tuple[()] = () | ||
AlexWaygood marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| def pipe_data_received(self, fd: int, data: bytes) -> None: ... | ||
| def pipe_connection_lost(self, fd: int, exc: Exception | None) -> None: ... | ||
| def process_exited(self) -> None: ... | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
should this be
?
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.
Or maybe Final.
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.
That would imply that you can't override it in subclasses, which seems questionable?
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.
Oh right. Well, if type checkers used standard inheritance rules you couldn't override this anyway since no other type is a subtype of
tuple[()].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.
Actually this makes mypy unhappy, it now also wants you to use a ClassVar annotation in all child classes. I'm inclined to go back to the bare
tuple[()]annotation unless it causes concrete problems with some type checker.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.
yeah that's fine