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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ def add_invertible_flag(
add_invertible_flag(
"--strict-bytes",
default=False,
strict_flag=False,
strict_flag=True,
help="Disable treating bytearray and memoryview as subtypes of bytes",
group=strictness_group,
)
Expand Down
1 change: 0 additions & 1 deletion mypy_self_check.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[mypy]

strict = True
strict_bytes = True
local_partial_types = True
disallow_any_unimported = True
show_traceback = True
Expand Down
17 changes: 17 additions & 0 deletions test-data/unit/check-flags.test
Original file line number Diff line number Diff line change
Expand Up @@ -2408,6 +2408,23 @@ f(bytearray(b"asdf"))
f(memoryview(b"asdf"))
[builtins fixtures/primitives.pyi]

[case testStrictBytesDisabledByDefault]
# TODO: probably change this default in Mypy v2.0, with https://github.com/python/mypy/pull/18371
# (this would also obsolete the testStrictBytesEnabledByStrict test, below)
def f(x: bytes) -> None: ...
f(bytearray(b"asdf"))
f(memoryview(b"asdf"))
[builtins fixtures/primitives.pyi]

[case testStrictBytesEnabledByStrict]
# flags: --strict --disable-error-code type-arg
# The type-arg thing is just work around the primitives.pyi isinstance Tuple not having type parameters,
# which isn't important for this.
def f(x: bytes) -> None: ...
f(bytearray(b"asdf")) # E: Argument 1 to "f" has incompatible type "bytearray"; expected "bytes"
f(memoryview(b"asdf")) # E: Argument 1 to "f" has incompatible type "memoryview"; expected "bytes"
[builtins fixtures/primitives.pyi]

[case testNoCrashFollowImportsForStubs]
# flags: --config-file tmp/mypy.ini
{**{"x": "y"}}
Expand Down