Skip to content

Commit 2587d64

Browse files
committed
fix up more
1 parent cd0d27c commit 2587d64

File tree

4 files changed

+62
-57
lines changed

4 files changed

+62
-57
lines changed

mypy/options.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,9 @@ def process_strict_bytes(self) -> None:
471471
# backwards compatibility
472472
self.disable_bytearray_promotion = True
473473
self.disable_memoryview_promotion = True
474-
elif self.disable_bytearray_promotion and self.disable_memoryview_promotion:
475-
# forwards compatibility
476-
self.strict_bytes = True
474+
else:
475+
self.disable_bytearray_promotion = False
476+
self.disable_memoryview_promotion = False
477477

478478
def apply_changes(self, changes: dict[str, object]) -> Options:
479479
# Note: effects of this method *must* be idempotent.

mypyc/test-data/run-bytes.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ def test_bytearray_type_object() -> None:
305305
b = bytearray()
306306
assert type(b) is bytearray
307307

308-
def fb(b: bytes | bytearray) -> str:
308+
def fb(b: bytes) -> str:
309309
return "xy"
310310

311311
def test_bytearray_passed_into_bytes() -> None:

test-data/unit/check-flags.test

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2542,42 +2542,6 @@ x: int = "" # E: Incompatible types in assignment (expression has type "str", v
25422542
# flags: --hide-error-codes
25432543
x: int = "" # E: Incompatible types in assignment (expression has type "str", variable has type "int")
25442544

2545-
[case testDisableBytearrayPromotion]
2546-
# flags: --disable-bytearray-promotion --strict-equality --warn-unreachable
2547-
def f(x: bytes) -> None: ...
2548-
f(bytearray(b"asdf")) # E: Argument 1 to "f" has incompatible type "bytearray"; expected "bytes"
2549-
f(memoryview(b"asdf"))
2550-
ba = bytearray(b"")
2551-
if ba == b"":
2552-
f(ba) # E: Argument 1 to "f" has incompatible type "bytearray"; expected "bytes"
2553-
if b"" == ba:
2554-
f(ba) # E: Argument 1 to "f" has incompatible type "bytearray"; expected "bytes"
2555-
if ba == bytes():
2556-
f(ba) # E: Argument 1 to "f" has incompatible type "bytearray"; expected "bytes"
2557-
if bytes() == ba:
2558-
f(ba) # E: Argument 1 to "f" has incompatible type "bytearray"; expected "bytes"
2559-
[builtins fixtures/primitives.pyi]
2560-
2561-
[case testDisableMemoryviewPromotion]
2562-
# flags: --disable-memoryview-promotion
2563-
def f(x: bytes) -> None: ...
2564-
f(bytearray(b"asdf"))
2565-
f(memoryview(b"asdf")) # E: Argument 1 to "f" has incompatible type "memoryview"; expected "bytes"
2566-
[builtins fixtures/primitives.pyi]
2567-
2568-
[case testDisableBytearrayMemoryviewPromotionStrictEquality]
2569-
# flags: --strict-equality --strict-bytes
2570-
def f(x: bytes, y: bytearray, z: memoryview) -> None:
2571-
x == y
2572-
y == z
2573-
x == z
2574-
97 in x
2575-
97 in y
2576-
97 in z
2577-
x in y
2578-
x in z
2579-
[builtins fixtures/primitives.pyi]
2580-
25812545
[case testStrictBytes]
25822546
# flags: --strict-bytes
25832547
def f(x: bytes) -> None: ...
@@ -2592,23 +2556,6 @@ f(bytearray(b"asdf"))
25922556
f(memoryview(b"asdf"))
25932557
[builtins fixtures/primitives.pyi]
25942558

2595-
[case testStrictBytesDisabledByDefault]
2596-
# TODO: probably change this default in Mypy v2.0, with https://github.com/python/mypy/pull/18371
2597-
# (this would also obsolete the testStrictBytesEnabledByStrict test, below)
2598-
def f(x: bytes) -> None: ...
2599-
f(bytearray(b"asdf"))
2600-
f(memoryview(b"asdf"))
2601-
[builtins fixtures/primitives.pyi]
2602-
2603-
[case testStrictBytesEnabledByStrict]
2604-
# flags: --strict --disable-error-code type-arg
2605-
# The type-arg thing is just work around the primitives.pyi isinstance Tuple not having type parameters,
2606-
# which isn't important for this.
2607-
def f(x: bytes) -> None: ...
2608-
f(bytearray(b"asdf")) # E: Argument 1 to "f" has incompatible type "bytearray"; expected "bytes"
2609-
f(memoryview(b"asdf")) # E: Argument 1 to "f" has incompatible type "memoryview"; expected "bytes"
2610-
[builtins fixtures/primitives.pyi]
2611-
26122559
[case testNoCrashFollowImportsForStubs]
26132560
# flags: --config-file tmp/mypy.ini
26142561
{**{"x": "y"}}

test-data/unit/check-type-promotion.test

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,64 @@ def f(x: bytes) -> None: pass
3333
f(memoryview(b''))
3434
[builtins fixtures/primitives.pyi]
3535

36+
[case testDisableBytearrayMemoryviewPromotion]
37+
# flags: --strict-bytes --strict-equality --warn-unreachable
38+
def f(x: bytes) -> None: ...
39+
f(bytearray(b"asdf")) # E: Argument 1 to "f" has incompatible type "bytearray"; expected "bytes"
40+
f(memoryview(b"asdf")) # E: Argument 1 to "f" has incompatible type "memoryview"; expected "bytes"
41+
ba = bytearray(b"")
42+
if ba == b"":
43+
f(ba) # E: Argument 1 to "f" has incompatible type "bytearray"; expected "bytes"
44+
if b"" == ba:
45+
f(ba) # E: Argument 1 to "f" has incompatible type "bytearray"; expected "bytes"
46+
if ba == bytes():
47+
f(ba) # E: Argument 1 to "f" has incompatible type "bytearray"; expected "bytes"
48+
if bytes() == ba:
49+
f(ba) # E: Argument 1 to "f" has incompatible type "bytearray"; expected "bytes"
50+
[builtins fixtures/primitives.pyi]
51+
52+
[case testEnableBytearrayMemoryviewPromotion]
53+
# flags: --no-strict-bytes --strict-equality --warn-unreachable
54+
def f(x: bytes) -> None: ...
55+
f(bytearray(b"asdf"))
56+
f(memoryview(b"asdf"))
57+
ba = bytearray(b"")
58+
if ba == b"":
59+
f(ba)
60+
if b"" == ba:
61+
f(ba)
62+
if ba == bytes():
63+
f(ba)
64+
if bytes() == ba:
65+
f(ba)
66+
[builtins fixtures/primitives.pyi]
67+
68+
[case testDisableBytearrayMemoryviewPromotionStrictEquality]
69+
# flags: --strict-equality --strict-bytes
70+
def f(x: bytes, y: bytearray, z: memoryview) -> None:
71+
x == y
72+
y == z
73+
x == z
74+
97 in x
75+
97 in y
76+
97 in z
77+
x in y
78+
x in z
79+
[builtins fixtures/primitives.pyi]
80+
81+
[case testEnableBytearrayMemoryviewPromotionStrictEquality]
82+
# flags: --strict-equality --no-strict-bytes
83+
def f(x: bytes, y: bytearray, z: memoryview) -> None:
84+
x == y
85+
y == z
86+
x == z
87+
97 in x
88+
97 in y
89+
97 in z
90+
x in y
91+
x in z
92+
[builtins fixtures/primitives.pyi]
93+
3694
[case testNarrowingDownFromPromoteTargetType]
3795
y = 0.0
3896
y = 1

0 commit comments

Comments
 (0)