Skip to content

add --strict-bytes to --strict #19049

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

wyattscarpenter
Copy link
Contributor

@wyattscarpenter wyattscarpenter commented May 7, 2025

This is a check that ensures static correctness, so it is useful to have in --strict. Unlike making this the default behavior eventually in 2.0, which we are also planning to do, it can be added to --strict immediately due to --strict having looser backwards-compatibility requirements (or so I interpret --strict's documentation). This PR also includes tests, for --strict and also for no flags.

This is a check that ensures static correctness, so it is useful to have here. Unlike making this the default behavior eventually in 2.0 (which we are also planning to do), it can be added to --strict immediately due to --strict having looser backwards-compatibility requirements (or so I interpret its documentation). This commit also includes tests.
@wyattscarpenter wyattscarpenter marked this pull request as draft May 8, 2025 00:06

This comment has been minimized.

@wyattscarpenter wyattscarpenter marked this pull request as ready for review May 8, 2025 01:42

This comment has been minimized.

Copy link
Contributor

github-actions bot commented May 8, 2025

Diff from mypy_primer, showing the effect of this PR on open source code:

mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
+ pymongo/network_layer.py:351: error: Argument 1 to "recv_into" of "NetworkingInterface" has incompatible type "memoryview[int]"; expected "bytes"  [arg-type]
+ pymongo/network_layer.py:767: error: Argument 1 to "decompress" has incompatible type "memoryview[int]"; expected "bytes"  [arg-type]
+ pymongo/network_layer.py:769: error: Incompatible types in assignment (expression has type "memoryview[int]", variable has type "bytes")  [assignment]
+ pymongo/message.py:738: error: Argument 1 to "_inflate_bson" has incompatible type "memoryview[int]"; expected "bytes"  [arg-type]
+ pymongo/asynchronous/encryption.py:212: error: Incompatible types in assignment (expression has type "memoryview[int]", variable has type "bytes")  [assignment]

boostedblob (https://github.com/hauntsaninja/boostedblob)
+ boostedblob/write.py:67: error: Argument "data" to "Request" has incompatible type "Union[bytes, bytearray, memoryview[int]]"; expected "Union[Dict[str, Any], bytes, None]"  [arg-type]
+ boostedblob/write.py:88: error: Argument "data" to "Request" has incompatible type "Union[bytes, bytearray, memoryview[int]]"; expected "Union[Dict[str, Any], bytes, None]"  [arg-type]
+ boostedblob/write.py:411: error: Argument "data" to "Request" has incompatible type "Union[bytes, bytearray, memoryview[int]]"; expected "Union[Dict[str, Any], bytes, None]"  [arg-type]

bokeh (https://github.com/bokeh/bokeh)
+ src/bokeh/core/serialization.py: note: In member "_decode_bytes" of class "Deserializer":
+ src/bokeh/core/serialization.py:618:16: error: Incompatible return value type (got "bytes | memoryview[int]", expected "bytes")  [return-value]

websockets (https://github.com/aaugustin/websockets)
+ src/websockets/streams.py:52: error: Incompatible return value type (got "bytearray", expected "bytes")  [return-value]
+ src/websockets/streams.py:75: error: Incompatible return value type (got "bytearray", expected "bytes")  [return-value]
+ src/websockets/streams.py:97: error: Incompatible return value type (got "bytearray", expected "bytes")  [return-value]
+ src/websockets/frames.py:174: error: Argument 1 to "parse" of "Close" has incompatible type "bytes | bytearray | memoryview[int]"; expected "bytes"  [arg-type]
+ src/websockets/frames.py:328: error: Argument 1 to "apply_mask" has incompatible type "bytes | bytearray | memoryview[int]"; expected "bytes"  [arg-type]
+ src/websockets/frames.py:330: error: Incompatible types in assignment (expression has type "bytes | bytearray | memoryview[int]", variable has type "bytes")  [assignment]
+ src/websockets/protocol.py:706: error: Argument 1 to "parse" of "Close" has incompatible type "bytes | bytearray | memoryview[int]"; expected "bytes"  [arg-type]
+ src/websockets/extensions/permessage_deflate.py:137: error: Incompatible types in assignment (expression has type "bytes | bytearray | memoryview[int]", variable has type "bytes")  [assignment]
+ src/websockets/extensions/permessage_deflate.py:194: error: Incompatible types in assignment (expression has type "memoryview[int]", variable has type "bytes")  [assignment]
+ src/websockets/asyncio/messages.py:246: error: Incompatible types in "yield" (actual type "bytes | bytearray | memoryview[int]", expected type "str | bytes")  [misc]
+ src/websockets/asyncio/messages.py:260: error: Incompatible types in "yield" (actual type "bytes | bytearray | memoryview[int]", expected type "str | bytes")  [misc]
+ src/websockets/asyncio/connection.py:487: error: Argument 1 to "send_text" of "Protocol" has incompatible type "bytes | memoryview[Any]"; expected "bytes"  [arg-type]
+ src/websockets/asyncio/connection.py:489: error: Argument 1 to "send_binary" of "Protocol" has incompatible type "bytes | memoryview[Any]"; expected "bytes"  [arg-type]
+ src/websockets/sync/messages.py:258: error: Incompatible types in "yield" (actual type "bytes | bytearray | memoryview[int]", expected type "str | bytes")  [misc]
+ src/websockets/sync/messages.py:269: error: Incompatible types in "yield" (actual type "bytes | bytearray | memoryview[int]", expected type "str | bytes")  [misc]
+ src/websockets/legacy/framing.py:117: error: Argument 3 to "Frame" has incompatible type "bytes | bytearray | memoryview[int]"; expected "bytes"  [arg-type]
+ src/websockets/sync/connection.py:486: error: Argument 1 to "send_text" of "Protocol" has incompatible type "bytes | memoryview[Any]"; expected "bytes"  [arg-type]
+ src/websockets/sync/connection.py:488: error: Argument 1 to "send_binary" of "Protocol" has incompatible type "bytes | memoryview[Any]"; expected "bytes"  [arg-type]
+ src/websockets/legacy/protocol.py:631: error: Argument 1 to "prepare_data" has incompatible type "str | bytes | memoryview[Any]"; expected "str | bytes"  [arg-type]
+ src/websockets/sync/client.py:645: error: Argument 1 to "send" of "SSLSSLSocket" has incompatible type "memoryview[int]"; expected "bytes"  [arg-type]

python-chess (https://github.com/niklasf/python-chess)
+ chess/gaviota.py:1738: error: Incompatible types in assignment (expression has type "bytearray", variable has type "bytes")  [assignment]

werkzeug (https://github.com/pallets/werkzeug)
+ src/werkzeug/sansio/multipart.py:174: error: Argument 1 to "_parse_headers" of "MultipartDecoder" has incompatible type "bytearray"; expected "bytes"  [arg-type]
+ src/werkzeug/sansio/multipart.py:213: error: Argument 1 to "_parse_data" of "MultipartDecoder" has incompatible type "bytearray"; expected "bytes"  [arg-type]
+ src/werkzeug/sansio/multipart.py:220: error: Argument 1 to "_parse_data" of "MultipartDecoder" has incompatible type "bytearray"; expected "bytes"  [arg-type]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant