Python 3.17 中待移除的項目¶
-
collections.abc.ByteStringis scheduled for removal in Python 3.17.Use
isinstance(obj, collections.abc.Buffer)to test ifobjimplements the buffer protocol at runtime. For use in type annotations, either useBufferor a union that explicitly specifies the types your code supports (e.g.,bytes | bytearray | memoryview).ByteStringwas originally intended to be an abstract class that would serve as a supertype of bothbytesandbytearray. However, since the ABC never had any methods, knowing that an object was an instance ofByteStringnever actually told you anything useful about the object. Other common buffer types such asmemoryviewwere 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.)
-
在 Python 3.14 之前,舊式聯集是使用私有類別
typing._UnionGenericAlias實作的。這個類別不再被需要,但為了向後相容性而保留,並計劃將在 Python 3.17 中移除。使用者應該改用文件中記錄的內省輔助函式,例如typing.get_origin()和typing.get_args(),或者依賴私有實作細節。typing.ByteString, deprecated since Python 3.9, is scheduled for removal in Python 3.17.Use
isinstance(obj, collections.abc.Buffer)to test ifobjimplements the buffer protocol at runtime. For use in type annotations, either useBufferor a union that explicitly specifies the types your code supports (e.g.,bytes | bytearray | memoryview).ByteStringwas originally intended to be an abstract class that would serve as a supertype of bothbytesandbytearray. However, since the ABC never had any methods, knowing that an object was an instance ofByteStringnever actually told you anything useful about the object. Other common buffer types such asmemoryviewwere 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.)