You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PEP 688 has been accepted and implemented in Python 3.12. For Python 3.12 and up, this provides a clean, protocol-based way to implement buffers.
Unfortunately, we still can't directly represent buffer types on earlier Python versions. I'd like to propose the following approach:
We pretend that typing_extensions.Buffer is a Protocol with a __buffer__ method even before 3.12.
We create __buffer__ methods on buffer classes without a version condition, even though the method does not actually exist before 3.12.
Now, we can define protocols that combine __buffer__ with other methods, such as the current _typeshed.SliceableBuffer.
The downside is that we're lying about the existence of the __buffer__ method, so that type checkers will not catch places where users call the method on Python < 3.12. However, hopefully this will be rare, and it is outweighed by the benefit that we can now talk about arbitrary buffer types, including third-party ones, without the big unions we're currently using in _typeshed.
The text was updated successfully, but these errors were encountered:
PEP 688 has been accepted and implemented in Python 3.12. For Python 3.12 and up, this provides a clean, protocol-based way to implement buffers.
Unfortunately, we still can't directly represent buffer types on earlier Python versions. I'd like to propose the following approach:
typing_extensions.Buffer
is a Protocol with a__buffer__
method even before 3.12.__buffer__
methods on buffer classes without a version condition, even though the method does not actually exist before 3.12.__buffer__
with other methods, such as the current_typeshed.SliceableBuffer
.The downside is that we're lying about the existence of the
__buffer__
method, so that type checkers will not catch places where users call the method on Python < 3.12. However, hopefully this will be rare, and it is outweighed by the benefit that we can now talk about arbitrary buffer types, including third-party ones, without the big unions we're currently using in_typeshed
.The text was updated successfully, but these errors were encountered: