Uh oh!
There was an error while loading. Please reload this page.
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.
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.
| 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.
bytes and bytearray specifically are treated differently. Arbitrary non-iterable buffers (e.g., pickle.PickleBuffer) don't work.
| # 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.
It explicitly accepts only bytes, not bytearray.
| _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.
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.
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.
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.
One more case is bytes only for BTPROTO_HCI on NetBSD, but I don't think this exotic case is worth mentioning.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
JelleZijlstra
commented
Oct 28, 2022
Thanks @srittau! |
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
No description provided.