Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ from typing import ( # noqa: Y022
IO,
Any,
BinaryIO,
ByteString,
ClassVar,
Generic,
Mapping,
Expand Down Expand Up @@ -592,7 +591,7 @@ class str(Sequence[str]):
def __rmul__(self, __value: SupportsIndex) -> str: ... # type: ignore[misc]
def __getnewargs__(self) -> tuple[str]: ...

class bytes(ByteString):
class bytes(Sequence[int]):
@overload
def __new__(cls, __o: Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | ReadableBuffer) -> Self: ...
@overload
Expand Down Expand Up @@ -697,7 +696,7 @@ class bytes(ByteString):

def __buffer__(self, __flags: int) -> memoryview: ...

class bytearray(MutableSequence[int], ByteString):
class bytearray(MutableSequence[int]):
@overload
def __init__(self) -> None: ...
@overload
Expand Down
2 changes: 1 addition & 1 deletion stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ class TextIO(IO[str]):
@abstractmethod
def __enter__(self) -> TextIO: ...

class ByteString(Sequence[int], metaclass=ABCMeta): ...
ByteString: typing_extensions.TypeAlias = bytes | bytearray | memoryview

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this in person a bit. "bytes | bytearray | memoryview" matches the documented semantics of this symbol (https://docs.python.org/3.11/library/typing.html#typing.ByteString), but the previous stubs here in typeshed didn't include memoryview, which is not a Sequence. It's a mess either way and that's why we deprecated this thing, but we may have to adjust this definition if people complain about it.


# Functions

Expand Down
1 change: 1 addition & 0 deletions tests/stubtest_allowlists/py37.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ collections.AsyncGenerator.ag_await
collections.AsyncGenerator.ag_code
collections.AsyncGenerator.ag_frame
collections.AsyncGenerator.ag_running
collections.ByteString # see comments in py3_common.txt
collections.Callable
collections.Mapping.__reversed__ # Set to None at runtime for a better error message
contextvars.ContextVar.get
Expand Down
1 change: 1 addition & 0 deletions tests/stubtest_allowlists/py38.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ collections.AsyncGenerator.ag_await
collections.AsyncGenerator.ag_code
collections.AsyncGenerator.ag_frame
collections.AsyncGenerator.ag_running
collections.ByteString # see comments in py3_common.txt
collections.Callable
collections.ItemsView.__reversed__
collections.KeysView.__reversed__
Expand Down
1 change: 1 addition & 0 deletions tests/stubtest_allowlists/py39.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ collections.AsyncGenerator.ag_await
collections.AsyncGenerator.ag_code
collections.AsyncGenerator.ag_frame
collections.AsyncGenerator.ag_running
collections.ByteString # see comments in py3_common.txt
collections.Callable
collections.Mapping.__reversed__ # Set to None at runtime for a better error message
collections.ItemsView.__reversed__
Expand Down
5 changes: 5 additions & 0 deletions tests/stubtest_allowlists/py3_common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,11 @@ xml.etree.ElementTree.Element.__iter__
xml.etree.cElementTree.Element.__iter__
typing.IO.__iter__ # See https://github.com/python/typeshed/commit/97bc450acd60c1bcdafef3ce8fbe3b95a9c0cac3

# Pretend typing.ByteString is a Union, to better match its documented semantics.
# As a side effect, this changes the definition of collections.abc.ByteString, which is okay,
# because it's not an ABC that makes any sense and was deprecated in 3.12
_collections_abc.ByteString

# ==========
# Missing from deprecated modules
# Any of these can be added if someone needs them
Expand Down