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
Experiment: remove bytearray -> bytes promotion #12661
Draft
JelleZijlstra
wants to merge
2
commits into
python:master
Choose a base branch
from
JelleZijlstra:bytearray
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Help gauge the impact of python#12657
This comment has been minimized.
This comment has been minimized.
Quick notes:
|
JelleZijlstra
added a commit
to JelleZijlstra/typeshed
that referenced
this issue
Apr 23, 2022
Most of these accept any buffer object. Found with python/mypy#12661 (comment)
JelleZijlstra
added a commit
to JelleZijlstra/typeshed
that referenced
this issue
Apr 23, 2022
Another from python/mypy#12661 (comment) (the hit in optuna)
anyio one is an incorrect annotation, fixed in agronholm/anyio#434 |
Diff from mypy_primer, showing the effect of this PR on open source code: psycopg (https://github.com/psycopg/psycopg)
+ psycopg/psycopg/adapt.py:90: error: Non-overlapping equality check (left operand type: "memoryview", right operand type: "Literal[b'\\\\']") [comparison-overlap]
+ psycopg/psycopg/sql.py:395: error: Incompatible return value type (got "Union[bytes, bytearray, memoryview]", expected "bytes") [return-value]
+ psycopg/psycopg/copy.py:146: error: Argument 1 to "parse_row" of "Formatter" has incompatible type "memoryview"; expected "bytes" [arg-type]
+ psycopg/psycopg/copy.py:320: error: Argument 1 to "put" of "Queue" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/copy.py:325: error: Argument 1 to "put" of "Queue" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/copy.py:423: error: Argument 1 to "put" of "Queue" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/copy.py:428: error: Argument 1 to "put" of "Queue" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/copy.py:484: error: Return type "Union[bytes, bytearray, memoryview]" of "write" incompatible with return type "bytes" in supertype "Formatter" [override]
+ psycopg/psycopg/copy.py:497: error: Incompatible return value type (got "bytearray", expected "bytes") [return-value]
+ psycopg/psycopg/copy.py:503: error: Incompatible return value type (got "bytearray", expected "bytes") [return-value]
+ psycopg/psycopg/copy.py:537: error: Return type "Union[bytes, bytearray, memoryview]" of "write" incompatible with return type "bytes" in supertype "Formatter" [override]
+ psycopg/psycopg/copy.py:554: error: Incompatible return value type (got "bytearray", expected "bytes") [return-value]
+ psycopg/psycopg/copy.py:575: error: Incompatible return value type (got "bytearray", expected "bytes") [return-value]
+ psycopg/psycopg/copy.py:602: error: Argument 2 to "sub" of "Pattern" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/cursor.py:442: error: Argument 2 to "send_query_params" of "PGconn" has incompatible type "Optional[Sequence[Union[bytes, bytearray, memoryview, None]]]"; expected "Optional[Sequence[Optional[bytes]]]" [arg-type]
+ psycopg/psycopg/cursor.py:584: error: Argument 2 to "send_query_prepared" of "PGconn" has incompatible type "Optional[Sequence[Union[bytes, bytearray, memoryview, None]]]"; expected "Optional[Sequence[Optional[bytes]]]" [arg-type]
+ psycopg/psycopg/types/string.py:86: error: Incompatible return value type (got "Union[bytes, bytearray, memoryview]", expected "Union[bytes, str]") [return-value]
+ psycopg/psycopg/types/string.py:127: error: Non-overlapping equality check (left operand type: "memoryview", right operand type: "Literal[b'\\\\000']") [comparison-overlap]
+ psycopg/psycopg/types/string.py:151: error: Incompatible return value type (got "memoryview", expected "bytes") [return-value]
+ psycopg/psycopg/types/string.py:151: error: Argument 1 to "unescape_bytea" of "Escaping" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/string.py:159: error: Incompatible return value type (got "Union[bytes, bytearray, memoryview]", expected "bytes") [return-value]
+ psycopg/psycopg/types/range.py:338: error: Argument 1 to "search" of "Pattern" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/range.py:339: error: Argument 2 to "sub" of "Pattern" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/range.py:344: error: Argument 1 to "append" of "list" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/range.py:349: error: Argument 1 to "append" of "list" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/range.py:432: error: Argument 1 to "match" of "Pattern" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/numeric.py:191: error: Return type "Union[bytes, bytearray, memoryview]" of "dump" incompatible with return type "bytes" in supertype "_IntDumper" [override]
+ psycopg/psycopg/types/numeric.py:224: error: Argument 1 has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/numeric.py:232: error: Argument 1 has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/numeric.py:240: error: Argument 1 has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/numeric.py:248: error: Argument 1 has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/numeric.py:262: error: Argument 1 has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/numeric.py:270: error: Argument 1 has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/numeric.py:331: error: Argument 1 has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/json.py:158: error: Incompatible types in assignment (expression has type "Callable[[Union[str, bytes], DefaultNamedArg(Optional[Type[JSONDecoder]], 'cls'), DefaultNamedArg(Optional[Callable[[Dict[Any, Any]], Any]], 'object_hook'), DefaultNamedArg(Optional[Callable[[str], Any]], 'parse_float'), DefaultNamedArg(Optional[Callable[[str], Any]], 'parse_int'), DefaultNamedArg(Optional[Callable[[str], Any]], 'parse_constant'), DefaultNamedArg(Optional[Callable[[List[Tuple[Any, Any]]], Any]], 'object_pairs_hook'), KwArg(Any)], Any]", variable has type "Callable[[Union[str, bytes, bytearray]], Any]") [assignment]
+ psycopg/psycopg/types/enum.py:40: error: Unused "type: ignore" comment
+ psycopg/psycopg/types/datetime.py:272: error: Argument 1 has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/datetime.py:287: error: Argument 1 to "match" of "Pattern" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/datetime.py:314: error: Argument 1 has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/datetime.py:336: error: Argument 1 to "match" of "Pattern" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/datetime.py:371: error: Argument 1 has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/datetime.py:431: error: Argument 1 to "match" of "Pattern" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/datetime.py:478: error: Argument 1 has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/datetime.py:511: error: Argument 1 to "match" of "Pattern" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/datetime.py:577: error: Argument 1 has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/datetime.py:626: error: Argument 1 to "match" of "Pattern" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/datetime.py:670: error: Argument 1 has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/composite.py:46: error: Argument 1 to "search" of "Pattern" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/composite.py:47: error: Argument 2 to "sub" of "Pattern" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/composite.py:49: error: Argument 1 to "append" of "list" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/composite.py:137: error: Argument 1 to "_parse_record" of "BaseCompositeLoader" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/composite.py:148: error: Argument 1 to "_config_types" of "RecordBinaryLoader" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/composite.py:153: error: Generator has incompatible item type "Union[bytes, bytearray, memoryview, None]"; expected "Optional[bytes]" [misc]
+ psycopg/psycopg/types/composite.py:154: error: Argument 1 to "_walk_record" of "RecordBinaryLoader" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/composite.py:182: error: Argument 1 to "_config_types" of "CompositeLoader" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/composite.py:189: error: Argument 1 to "_parse_record" of "BaseCompositeLoader" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/array.py:153: error: Argument 1 has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/array.py:157: error: Argument 1 to "append" of "list" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/array.py:285: error: Argument 1 to "append" of "list" has incompatible type "Union[bytes, bytearray, memoryview, Any]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/array.py:336: error: Argument 1 to "finditer" of "Pattern" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/array.py:393: error: Argument 1 has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/array.py:400: error: Argument 1 has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/dbapi20.py:71: error: Argument 1 to "dump" of "BytesDumper" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/multirange.py:229: error: Argument 1 to "append" of "list" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ psycopg/psycopg/types/multirange.py:250: error: Argument 1 to "append" of "list" has incompatible type "Union[bytes, bytearray, memoryview]"; expected "bytes" [arg-type]
+ tests/test_sql.py:53: error: Non-overlapping equality check (left operand type: "memoryview", right operand type: "Literal[b'\\\\']") [comparison-overlap]
+ tests/test_sql.py:55: error: Non-overlapping equality check (left operand type: "memoryview", right operand type: "Literal[b'\\\\000']") [comparison-overlap]
+ tests/test_sql.py:59: error: Non-overlapping equality check (left operand type: "memoryview", right operand type: "Literal[b'\\\\\\\\']") [comparison-overlap]
+ tests/test_sql.py:61: error: Non-overlapping equality check (left operand type: "memoryview", right operand type: "Literal[b'\\\\\\\\000']") [comparison-overlap]
+ tests/types/test_json.py:120: error: Argument 1 to "set_json_loads" has incompatible type "Callable[[Union[str, bytes], DefaultNamedArg(Optional[Type[JSONDecoder]], 'cls'), DefaultNamedArg(Optional[Callable[[Dict[Any, Any]], Any]], 'object_hook'), DefaultNamedArg(Optional[Callable[[str], Any]], 'parse_float'), DefaultNamedArg(Optional[Callable[[str], Any]], 'parse_int'), DefaultNamedArg(Optional[Callable[[str], Any]], 'parse_constant'), DefaultNamedArg(Optional[Callable[[List[Tuple[Any, Any]]], Any]], 'object_pairs_hook'), KwArg(Any)], Any]"; expected "Callable[[Union[str, bytes, bytearray]], Any]" [arg-type]
+ tests/pq/test_escaping.py:32: error: Non-overlapping equality check (left operand type: "memoryview", right operand type: "bytes") [comparison-overlap]
+ tests/pq/test_escaping.py:71: error: Non-overlapping equality check (left operand type: "memoryview", right operand type: "bytes") [comparison-overlap]
+ tests/pq/test_escaping.py:110: error: Non-overlapping equality check (left operand type: "memoryview", right operand type: "bytes") [comparison-overlap]
+ tests/pq/test_escaping.py:127: error: Non-overlapping equality check (left operand type: "memoryview", right operand type: "bytes") [comparison-overlap]
+ tests/pq/test_escaping.py:153: error: Non-overlapping equality check (left operand type: "memoryview", right operand type: "bytes") [comparison-overlap]
+ tests/pq/test_escaping.py:174: error: Non-overlapping equality check (left operand type: "memoryview", right operand type: "bytes") [comparison-overlap]
+ psycopg/psycopg/types/hstore.py:73: error: Incompatible return value type (got "Union[bytes, bytearray, memoryview]", expected "bytes") [return-value]
git-revise (https://github.com/mystor/git-revise)
+ gitrevise/utils.py:86: error: Incompatible return value type (got "bytearray", expected "bytes")
aioredis (https://github.com/aio-libs/aioredis)
+ aioredis/connection.py:934: error: Item "memoryview" of "Union[bytes, memoryview]" has no attribute "split" [union-attr]
+ aioredis/connection.py:952: error: Argument 1 to "append" of "list" has incompatible type "Union[bytes, memoryview]"; expected "bytes" [arg-type]
+ aioredis/connection.py:981: error: Subclass of "bytes" and "memoryview" cannot exist: would have incompatible method signatures [unreachable]
+ aioredis/connection.py:987: error: Subclass of "bytes" and "memoryview" cannot exist: would have incompatible method signatures [unreachable]
- aioredis/client.py:4114: error: Incompatible types in assignment (expression has type "Dict[Union[bytes, str], Optional[Any]]", variable has type "Dict[Union[bytes, str, memoryview], Callable[[Dict[str, str]], Awaitable[None]]]") [assignment]
+ aioredis/client.py:4114: error: Incompatible types in assignment (expression has type "Dict[Union[bytes, str, memoryview], Optional[Any]]", variable has type "Dict[Union[bytes, str, memoryview], Callable[[Dict[str, str]], Awaitable[None]]]") [assignment]
- aioredis/client.py:4158: error: Argument 1 to "update" of "MutableMapping" has incompatible type "Dict[Union[bytes, str], Optional[Any]]"; expected "SupportsKeysAndGetItem[Union[bytes, str, memoryview], Callable[[Dict[str, str]], Awaitable[None]]]" [arg-type]
+ aioredis/client.py:4158: error: Argument 1 to "update" of "MutableMapping" has incompatible type "Dict[Union[bytes, str, memoryview], Optional[Any]]"; expected "SupportsKeysAndGetItem[Union[bytes, str, memoryview], Callable[[Dict[str, str]], Awaitable[None]]]" [arg-type]
anyio (https://github.com/agronholm/anyio)
+ src/anyio/_core/_sockets.py:417: error: Incompatible types in assignment (expression has type "Union[bytearray, bytes]", variable has type "bytes") [assignment]
- src/anyio/_backends/_asyncio.py:1571: error: Unused "type: ignore" comment
werkzeug (https://github.com/pallets/werkzeug)
+ src/werkzeug/_internal.py:144: error: Incompatible return value type (got "Union[bytes, bytearray]", expected "Union[str, bytes, None]") [return-value]
+ src/werkzeug/sansio/multipart.py:144: error: Argument 1 to "search" of "Pattern" has incompatible type "bytearray"; expected "bytes" [arg-type]
+ src/werkzeug/sansio/multipart.py:155: error: Argument 1 to "search" of "Pattern" has incompatible type "bytearray"; expected "bytes" [arg-type]
+ src/werkzeug/sansio/multipart.py:157: error: Argument 1 to "_parse_headers" of "MultipartDecoder" has incompatible type "bytearray"; expected "bytes" [arg-type]
+ src/werkzeug/sansio/multipart.py:190: error: Argument 1 to "search" of "Pattern" has incompatible type "bytearray"; expected "bytes" [arg-type]
+ src/werkzeug/routing.py:1209: error: Argument 1 has incompatible type "Union[bytes, bytearray]"; expected "bytes" [arg-type]
- tests/test_wrappers.py:1044: note: Use "-> None" if function does not return a value
- tests/test_wrappers.py:1072: error: Function is missing a return type annotation [no-untyped-def]
- tests/test_wrappers.py:1072: note: Use "-> None" if function does not return a value
- tests/test_wrappers.py:1078: error: Function is missing a return type annotation [no-untyped-def]
- tests/test_wrappers.py:1078: note: Use "-> None" if function does not return a value
- tests/test_wrappers.py:1084: error: Function is missing a return type annotation [no-untyped-def]
- tests/test_wrappers.py:1084: note: Use "-> None" if function does not return a value
- tests/test_wrappers.py:1109: note: (Skipping most remaining errors due to unresolved imports or missing stubs; fix these first)
+ tests/test_wrappers.py:1044: note: (Skipping most remaining errors due to unresolved imports or missing stubs; fix these first)
urllib3 (https://github.com/urllib3/urllib3)
+ src/urllib3/util/ssltransport.py:121: error: Argument 1 to "send" of "SSLTransport" has incompatible type "memoryview"; expected "bytes" [arg-type]
+ src/urllib3/connection.py:350: error: Argument 1 to "send" of "HTTPConnection" has incompatible type "bytearray"; expected "Union[bytes, IO[Any], Iterable[bytes], str]" [arg-type]
+ src/urllib3/connection.py:350: note: Following member(s) of "bytearray" have conflicts:
+ src/urllib3/connection.py:350: note: Expected:
+ src/urllib3/connection.py:350: note: def __iter__(self) -> Iterator[bytes]
+ src/urllib3/connection.py:350: note: Got:
+ src/urllib3/connection.py:350: note: def __iter__(self) -> Iterator[int]
+ test/test_ssltransport.py:59: error: Non-overlapping equality check (left operand type: "bytearray", right operand type: "Union[str, bytes]") [comparison-overlap]
+ test/test_ssltransport.py:540: error: Argument 1 to "sendall" of "SSLTransport" has incompatible type "bytearray"; expected "bytes" [arg-type]
+ test/with_dummyserver/test_chunked_transfer.py:200: error: Non-overlapping container check (element type: "bytes", container item type: "bytearray") [comparison-overlap]
+ test/with_dummyserver/test_chunked_transfer.py:229: error: Non-overlapping container check (element type: "bytes", container item type: "bytearray") [comparison-overlap]
+ test/with_dummyserver/test_chunked_transfer.py:259: error: Non-overlapping container check (element type: "bytes", container item type: "bytearray") [comparison-overlap]
python-chess (https://github.com/niklasf/python-chess)
+ chess/gaviota.py:1855: error: Incompatible types in assignment (expression has type "bytearray", variable has type "bytes")
websockets (https://github.com/aaugustin/websockets)
+ src/websockets/streams.py:52: error: Incompatible return value type (got "bytearray", expected "bytes")
+ src/websockets/streams.py:75: error: Incompatible return value type (got "bytearray", expected "bytes")
+ src/websockets/streams.py:97: error: Incompatible return value type (got "bytearray", expected "bytes")
bokeh (https://github.com/bokeh/bokeh)
+ bokeh/core/serialization.py: note: In member "_decode_bytes" of class "Deserializer":
+ bokeh/core/serialization.py:589:16: error: Incompatible return value type (got "Union[bytes, memoryview]", expected "bytes") [return-value]
aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/http_websocket.py:636: error: Incompatible types in assignment (expression has type "bytearray", variable has type "bytes") [assignment]
+ aiohttp/http_websocket.py:637: error: Argument 2 has incompatible type "bytes"; expected "bytearray" [arg-type]
yarl (https://github.com/aio-libs/yarl)
+ yarl/_quoting_py.py:63: error: Argument 1 to "match" of "Pattern" has incompatible type "bytearray"; expected "bytes" [arg-type]
core (https://github.com/home-assistant/core)
- homeassistant/components/sonos/media.py:138: error: Argument 1 to "int" has incompatible type "Optional[Any]"; expected "Union[str, bytes, array[Any], mmap, _CData, SupportsInt, SupportsIndex, SupportsTrunc]" [arg-type]
+ homeassistant/components/sonos/media.py:138: error: Argument 1 to "int" has incompatible type "Optional[Any]"; expected "Union[str, bytes, bytearray, memoryview, array[Any], mmap, _CData, SupportsInt, SupportsIndex, SupportsTrunc]" [arg-type]
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Help gauge the impact of #12657