Remoção pendente no Python 3.17¶
-
collections.abc.ByteString
is scheduled for removal in Python 3.17.Use
isinstance(obj, collections.abc.Buffer)
to test ifobj
implements the buffer protocol at runtime. For use in type annotations, either useBuffer
or a union that explicitly specifies the types your code supports (e.g.,bytes | bytearray | memoryview
).ByteString
was originally intended to be an abstract class that would serve as a supertype of bothbytes
andbytearray
. However, since the ABC never had any methods, knowing that an object was an instance ofByteString
never actually told you anything useful about the object. Other common buffer types such asmemoryview
were also never understood as subtypes ofByteString
(either at runtime or by static type checkers).See PEP 688 for more details. (Contributed by Shantanu Jain in gh-91896.)
-
Antes do Python 3.14, as uniões antigas eram implementadas usando a classe privada
typing._UnionGenericAlias
. Essa classe não é mais necessária para a implementação, mas foi mantida para compatibilidade com versões anteriores, com remoção prevista para o Python 3.17. Os usuários devem usar auxiliares de introspecção documentados, comotyping.get_origin()
etyping.get_args()
, em vez de depender de detalhes de implementação privada.typing.ByteString
, deprecated since Python 3.9, is scheduled for removal in Python 3.17.Use
isinstance(obj, collections.abc.Buffer)
to test ifobj
implements the buffer protocol at runtime. For use in type annotations, either useBuffer
or a union that explicitly specifies the types your code supports (e.g.,bytes | bytearray | memoryview
).ByteString
was originally intended to be an abstract class that would serve as a supertype of bothbytes
andbytearray
. However, since the ABC never had any methods, knowing that an object was an instance ofByteString
never actually told you anything useful about the object. Other common buffer types such asmemoryview
were also never understood as subtypes ofByteString
(either at runtime or by static type checkers).See PEP 688 for more details. (Contributed by Shantanu Jain in gh-91896.)