Skip to content

Attempt to clarify the ByteString situation #9783

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

Merged
merged 10 commits into from
May 28, 2023

Conversation

hauntsaninja
Copy link
Collaborator

@hauntsaninja hauntsaninja commented Feb 20, 2023

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
Copy link
Collaborator

srittau commented Feb 21, 2023

+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.

@github-actions

This comment has been minimized.

@AlexWaygood
Copy link
Member

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

@@ -715,7 +715,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
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
Member

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

@github-actions
Copy link
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