With PEP 688 being accepted and included in Python 3.12, we should accept and test for custom classes implementing the buffer protocol being passed to Parser.
Moreover, static type checkers will stop promoting bytearray/memoryview/etc. to bytes at some point, so let's anticipate that (has been tested with custom version of mypy).
With PEP 688 being accepted and included in Python 3.12, we should accept and test for custom classes implementing the buffer protocol being passed to
Parser
.Moreover, static type checkers will stop promoting
bytearray
/memoryview
/etc. tobytes
at some point, so let's anticipate that (has been tested with custom version of mypy).Mypy patch
```diff diff --git a/mypy/options.py b/mypy/options.py index 5ef6bc2a3..2642b6407 100644 --- a/mypy/options.py +++ b/mypy/options.py @@ -375,8 +375,8 @@ class Options: # (undocumented feature). self.export_ref_info = False - self.disable_bytearray_promotion = False - self.disable_memoryview_promotion = False + self.disable_bytearray_promotion = True + self.disable_memoryview_promotion = True self.force_uppercase_builtins = False self.force_union_syntax = False ```
Errors messages in current version with patched mypy
``` tests/unit/test_stream.py: note: In function "test_chain_types": tests/unit/test_stream.py:107: error: Argument 2 to "StreamChain" has incompatible type "bytearray"; expected "Streamable" [arg-type] tests/unit/test_stream.py:107: note: Following member(s) of "bytearray" have conflicts: tests/unit/test_stream.py:107: note: Expected: tests/unit/test_stream.py:107: note: def __iter__(self) -> Iterator[Streamable] tests/unit/test_stream.py:107: note: Got: tests/unit/test_stream.py:107: note: def __iter__(self) -> Iterator[int] tests/unit/test_stream.py:108: error: Argument 3 to "StreamChain" has incompatible type "memoryview"; expected "Streamable" [arg-type] tests/unit/test_stream.py:108: note: Following member(s) of "memoryview" have conflicts: tests/unit/test_stream.py:108: note: Expected: tests/unit/test_stream.py:108: note: def __iter__(self) -> Iterator[Streamable] tests/unit/test_stream.py:108: note: Got: tests/unit/test_stream.py:108: note: def __iter__(self) -> Iterator[int] Found 2 errors in 1 file (checked 26 source files) ```