diff --git a/mypy/main.py b/mypy/main.py index 7bd7215bbe2a..77351e2b56c5 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -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, ) diff --git a/mypy_self_check.ini b/mypy_self_check.ini index 816e6321c06f..8bf7a514f481 100644 --- a/mypy_self_check.ini +++ b/mypy_self_check.ini @@ -1,7 +1,6 @@ [mypy] strict = True -strict_bytes = True local_partial_types = True disallow_any_unimported = True show_traceback = True diff --git a/test-data/unit/check-flags.test b/test-data/unit/check-flags.test index 2a75b465099b..f628fdd68ce8 100644 --- a/test-data/unit/check-flags.test +++ b/test-data/unit/check-flags.test @@ -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"}}