Skip to content

Attempt to clarify the ByteString situation - #9783

Merged
hauntsaninja merged 10 commits into
python:mainfrom
hauntsaninja:byte-string
May 28, 2023
Merged

hauntsaninja merged 10 commits into
python:mainfrom
hauntsaninja:byte-string

Conversation

@hauntsaninja

@hauntsaninja hauntsaninja commented Feb 20, 2023 •

Copy link
Copy Markdown
Collaborator

See python/cpython#102092

This makes the behaviour of typing.ByteString better match its
documentation.

I also remove collections.abc.ByteString. There is no legitimate use
case for it. Let me know if you think there's a case where it would help
users to have this around.
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@hauntsaninja
hauntsaninja marked this pull request as draft February 20, 2023 23:50
@github-actions

This comment has been minimized.

@srittau

srittau commented Feb 21, 2023

Copy link
Copy Markdown
Collaborator

+1 at least for removing the subclass dependency to match runtime. (Even if the abc is registered at runtime.)

@github-actions

This comment has been minimized.

Comment thread tests/stubtest_allowlists/py3_common.txt Outdated
@github-actions

This comment has been minimized.

@AlexWaygood

Copy link
Copy Markdown
Member

For the record, I only clicked "approve" once; not sure how that happened!

Comment thread stdlib/typing.pyi
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.

@JelleZijlstra

Copy link
Copy Markdown
Member

This still marked as draft, @hauntsaninja shall we land it?

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@hauntsaninja
hauntsaninja marked this pull request as ready for review May 28, 2023 04:36
@hauntsaninja
hauntsaninja merged commit d6a85e2 into python:main May 28, 2023
@hauntsaninja
hauntsaninja deleted the byte-string branch May 28, 2023 04:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants