-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
ssl, socket, array: Improve bytes handling #8997
Conversation
_Address: TypeAlias = tuple[Any, ...] | str | ||
# AF_NETLINK, AF_TIPC) or strings/buffers (AF_UNIX). | ||
# See getsockaddrarg() in socketmodule.c. | ||
_Address: TypeAlias = tuple[Any, ...] | str | ReadableBuffer |
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.
All uses of this alias in the socket stubs allow a ReadableBuffer, so I put ReadableBuffer in the alias and removed explicit usage of bytes below.
The alias is used in some other stubs, but we can review those in a different PR.
@@ -21,15 +21,19 @@ class array(MutableSequence[_T], Generic[_T]): | |||
@property | |||
def itemsize(self) -> int: ... | |||
@overload | |||
def __init__(self: array[int], __typecode: _IntTypeCode, __initializer: bytes | Iterable[int] = ...) -> None: ... | |||
def __init__(self: array[int], __typecode: _IntTypeCode, __initializer: bytes | bytearray | Iterable[int] = ...) -> None: ... |
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.
bytes and bytearray specifically are treated differently. Arbitrary non-iterable buffers (e.g., pickle.PickleBuffer
) don't work.
@@ -788,5 +788,10 @@ if sys.version_info >= (3, 8): | |||
|
|||
# the 5th tuple item is an address | |||
def getaddrinfo( | |||
host: bytes | str | None, port: str | int | None, family: int = ..., type: int = ..., proto: int = ..., flags: int = ... | |||
host: bytes | str | None, |
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.
It explicitly accepts only bytes, not bytearray.
@@ -11,7 +11,7 @@ _PCTRTTT: TypeAlias = tuple[_PCTRTT, ...] | |||
_PeerCertRetDictType: TypeAlias = dict[str, str | _PCTRTTT | _PCTRTT] | |||
_PeerCertRetType: TypeAlias = _PeerCertRetDictType | bytes | None | |||
_EnumRetType: TypeAlias = list[tuple[bytes, str, set[str] | bool]] | |||
_PasswordType: TypeAlias = Union[Callable[[], str | bytes], str, bytes] | |||
_PasswordType: TypeAlias = Union[Callable[[], str | bytes | bytearray], str, bytes, bytearray] |
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.
The handling code handles bytes and bytearray, but not arbitrary buffers.
def match_hostname(cert: _PeerCertRetType, hostname: str) -> None: ... | ||
def RAND_add(__string: str | ReadableBuffer, __entropy: float) -> None: ... | ||
|
||
if sys.version_info < (3, 12): |
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.
Noticed this one is gone in 3.12.
timeout: int | ||
ticket_lifetime_hint: int | ||
has_ticket: bool | ||
@property |
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.
All these are read-only.
This comment has been minimized.
This comment has been minimized.
# AF_NETLINK, AF_TIPC) or strings (AF_UNIX). | ||
_Address: TypeAlias = tuple[Any, ...] | str | ||
# AF_NETLINK, AF_TIPC) or strings/buffers (AF_UNIX). | ||
# See getsockaddrarg() in socketmodule.c. |
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.
One more case is bytes
only for BTPROTO_HCI
on NetBSD, but I don't think this exotic case is worth mentioning.
Co-authored-by: Sebastian Rittau <[email protected]>
Thanks @srittau! |
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
No description provided.