Skip to content

collections.abc.ByteString is not equivalent to typing.ByteString #102092

Description

@hauntsaninja

There are two related, but different strands of conversation here:

However, there is an additional issue! collections.abc.ByteString is not an accurate replacement for typing.ByteString! collections.abc.ByteString only registers bytes and bytearray, whereas typing.ByteString is documented as also representing a memoryview. This is an issue regardless of the above two related conversations.

For this issue we could:

  • Move the documentation of typing.ByteString out from under the "Corresponding to collections in collections.abc" section to the "Other concrete types" section
  • Remove all mention of collections.abc.ByteString from typing.rst
  • Keep the mention of typing.ByteString as being deprecated, but change the reason. ByteString is not a generic type and collections.abc.ByteString is not a semantic replacement for it as above, so the current reason is wrong on two counts
  • Define typing.ByteString in typeshed as a simple Union, and not the Sequence[int] thing it is right now.
  • Define typing.ByteString as a Union in typing.py instead of the generic alias it is now(?)

Here's how this relates to the other two strands of conversation:

  • We should also remove the note about the bytes shorthand from the docs
  • We should deprecate both typing.ByteString and collections.abc.ByteString. I'm fine with going slow on the removal of typing.ByteString, since once it's a union in typeshed it's not causing much harm. But ideally we can remove collections.abc.ByteString in 3.14, since its isinstance behaviour is not what you want.

cc @JelleZijlstra

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dirtopic-typingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions