-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
collections.abc.ByteString is not equivalent to typing.ByteString #102092
Comments
It is highly confusing and its isinstance / issubclass behaviour does not match the documentation of typing.ByteString See python/cpython#102092
It is highly confusing and its isinstance / issubclass behaviour does not match the documentation of typing.ByteString See python/cpython#102092
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.
Thanks for the research here! Before we make changes in CPython it might make sense to wait for PEP 688 to be accepted (hopefully soon?), since that will affect what we should point users to. I'm not sure I see the issue, though. At runtime And
So while I am in favor of deprecating both ByteString objects, I don't see why we need to decouple them. |
I was hoping we could get away with treating I realise I was also kind of hoping we could just... pretend that Anyway, the claim is that
And while PEP 688 provides a path for something with better semantics (since users of So possible "fixes" are:
(python/typeshed#9783 doesn't surface issues and I couldn't find any
edit: it is also tested that memoryview is not a
|
I guess 2 might be more viable than I initially gave it credit for. This table is pretty clear that the interface for We can still go with option 3 and just deprecate instead of touching these, if we feel it's too messy. |
So your claim is essentially that there is a discrepancy between the implementation and the documentation for My preference is to deprecate both variants of
|
Okay, great. #102096 adds deprecation warnings to collections.abc.ByteString |
+1 on the deprecation and eventual removal. Since the situation is so muddled, and |
The bytes shorthand was removed in PEP 688: https://peps.python.org/pep-0688/#no-special-meaning-for-bytes I also remove the reference to `collections.abc.ByteString`, since that object is deprecated (python#91896) and has different semantics (python#102092) I think it would be good to backport this since the changes in the type system are immediate and apply to all versions of Python.
The bytes shorthand was removed in PEP 688: https://peps.python.org/pep-0688/#no-special-meaning-for-bytes I also remove the reference to `collections.abc.ByteString`, since that object is deprecated (#91896) and has different semantics (#102092)
The bytes shorthand was removed in PEP 688: https://peps.python.org/pep-0688/#no-special-meaning-for-bytes I also remove the reference to `collections.abc.ByteString`, since that object is deprecated (python#91896) and has different semantics (python#102092)
gh-102500: Remove mention of bytes shorthand (#104281) The bytes shorthand was removed in PEP 688: https://peps.python.org/pep-0688/#no-special-meaning-for-bytes The reference to collections.abc.ByteString is also removed, since that object is deprecated (#91896) and has different semantics (#102092) Although PEP 688 is new in Python 3.12, type checkers are expected to implement the new semantics for type annotations even if users are using an older version of Python, so this docs PR is backported to Python 3.11. Co-authored-by: Shantanu <[email protected]>
The bytes shorthand was removed in PEP 688: https://peps.python.org/pep-0688/#no-special-meaning-for-bytes I also remove the reference to `collections.abc.ByteString`, since that object is deprecated (python#91896) and has different semantics (python#102092)
See python/cpython#102092 This makes the behaviour of typing.ByteString better match its documentation.
I think we're done here -- the docs for both Feel free to reopen if there's something more to be done! |
There are two related, but different strands of conversation here:
collections.abc.ByteString
is useless and confusing: Deprecate and schedule removal of collections.abc.ByteString and typing.ByteString #91896bytes
can be used as a shorthand fortyping.ByteString
and includesmemoryview
andbytearray
https://peps.python.org/pep-0688/However, there is an additional issue!
collections.abc.ByteString
is not an accurate replacement fortyping.ByteString
!collections.abc.ByteString
only registersbytes
andbytearray
, whereastyping.ByteString
is documented as also representing a memoryview. This is an issue regardless of the above two related conversations.For this issue we could:
typing.ByteString
out from under the "Corresponding to collections in collections.abc" section to the "Other concrete types" sectioncollections.abc.ByteString
from typing.rsttyping.ByteString
as being deprecated, but change the reason. ByteString is not a generic type andcollections.abc.ByteString
is not a semantic replacement for it as above, so the current reason is wrong on two countstyping.ByteString
in typeshed as a simple Union, and not the Sequence[int] thing it is right now.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:
typing.ByteString
andcollections.abc.ByteString
. I'm fine with going slow on the removal oftyping.ByteString
, since once it's a union in typeshed it's not causing much harm. But ideally we can removecollections.abc.ByteString
in 3.14, since its isinstance behaviour is not what you want.cc @JelleZijlstra
The text was updated successfully, but these errors were encountered: