Skip to content

Commit f5c10aa

Browse files
committed
patch
1 parent c39f026 commit f5c10aa

File tree

4 files changed

+17
-28
lines changed

4 files changed

+17
-28
lines changed

mypy/main.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1405,9 +1405,9 @@ def set_strict_flags() -> None:
14051405
process_cache_map(parser, special_opts, options)
14061406

14071407
# Process --strict-bytes
1408-
if options.strict_bytes:
1409-
options.disable_bytearray_promotion = True
1410-
options.disable_memoryview_promotion = True
1408+
if not options.strict_bytes:
1409+
options.disable_bytearray_promotion = False
1410+
options.disable_memoryview_promotion = False
14111411

14121412
# An explicitly specified cache_fine_grained implies local_partial_types
14131413
# (because otherwise the cache is not compatible with dmypy)

mypyc/test-data/run-bytes.test

+9-9
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ def test_concat() -> None:
7979
assert type(b1) == bytes
8080
assert type(b2) == bytes
8181
assert type(b3) == bytes
82-
brr1: bytes = bytearray(3)
83-
brr2: bytes = bytearray(range(5))
82+
brr1: bytes | bytearray = bytearray(3)
83+
brr2: bytes | bytearray = bytearray(range(5))
8484
b4 = b1 + brr1
8585
assert b4 == b'123\x00\x00\x00'
8686
assert type(brr1) == bytearray
@@ -171,17 +171,17 @@ def test_bytes_slicing() -> None:
171171
from typing import Any
172172

173173
def test_basics() -> None:
174-
brr1: bytes = bytearray(3)
174+
brr1: bytes | bytearray = bytearray(3)
175175
assert brr1 == bytearray(b'\x00\x00\x00')
176176
assert brr1 == b'\x00\x00\x00'
177177
l = [10, 20, 30, 40]
178-
brr2: bytes = bytearray(l)
178+
brr2: bytes | bytearray = bytearray(l)
179179
assert brr2 == bytearray(b'\n\x14\x1e(')
180180
assert brr2 == b'\n\x14\x1e('
181-
brr3: bytes = bytearray(range(5))
181+
brr3: bytes | bytearray = bytearray(range(5))
182182
assert brr3 == bytearray(b'\x00\x01\x02\x03\x04')
183183
assert brr3 == b'\x00\x01\x02\x03\x04'
184-
brr4: bytes = bytearray('string', 'utf-8')
184+
brr4: bytes | bytearray = bytearray('string', 'utf-8')
185185
assert brr4 == bytearray(b'string')
186186
assert brr4 == b'string'
187187
assert len(brr1) == 3
@@ -197,7 +197,7 @@ def test_bytearray_passed_into_bytes() -> None:
197197

198198
[case testBytearraySlicing]
199199
def test_bytearray_slicing() -> None:
200-
b: bytes = bytearray(b'abcdefg')
200+
b: bytes | bytearray = bytearray(b'abcdefg')
201201
zero = int()
202202
ten = 10 + zero
203203
two = 2 + zero
@@ -231,7 +231,7 @@ def test_bytearray_slicing() -> None:
231231
from testutil import assertRaises
232232

233233
def test_bytearray_indexing() -> None:
234-
b: bytes = bytearray(b'\xae\x80\xfe\x15')
234+
b: bytes | bytearray = bytearray(b'\xae\x80\xfe\x15')
235235
assert b[0] == 174
236236
assert b[1] == 128
237237
assert b[2] == 254
@@ -260,7 +260,7 @@ def test_bytes_join() -> None:
260260
assert b' '.join([b'a', b'b']) == b'a b'
261261
assert b' '.join([]) == b''
262262

263-
x: bytes = bytearray(b' ')
263+
x: bytes | bytearray = bytearray(b' ')
264264
assert x.join([b'a', b'b']) == b'a b'
265265
assert type(x.join([b'a', b'b'])) == bytearray
266266

test-data/unit/check-flags.test

+3-16
Original file line numberDiff line numberDiff line change
@@ -2348,7 +2348,7 @@ x: int = "" # E: Incompatible types in assignment (expression has type "str", v
23482348
# flags: --disable-bytearray-promotion --strict-equality
23492349
def f(x: bytes) -> None: ...
23502350
f(bytearray(b"asdf")) # E: Argument 1 to "f" has incompatible type "bytearray"; expected "bytes"
2351-
f(memoryview(b"asdf"))
2351+
23522352
ba = bytearray(b"")
23532353
if ba == b"":
23542354
f(ba) # E: Argument 1 to "f" has incompatible type "bytearray"; expected "bytes"
@@ -2363,25 +2363,12 @@ if bytes() == ba:
23632363
[case testDisableMemoryviewPromotion]
23642364
# flags: --disable-memoryview-promotion
23652365
def f(x: bytes) -> None: ...
2366-
f(bytearray(b"asdf"))
2366+
23672367
f(memoryview(b"asdf")) # E: Argument 1 to "f" has incompatible type "memoryview"; expected "bytes"
23682368
[builtins fixtures/primitives.pyi]
23692369

23702370
[case testDisableBytearrayMemoryviewPromotionStrictEquality]
2371-
# flags: --disable-bytearray-promotion --disable-memoryview-promotion --strict-equality
2372-
def f(x: bytes, y: bytearray, z: memoryview) -> None:
2373-
x == y
2374-
y == z
2375-
x == z
2376-
97 in x
2377-
97 in y
2378-
97 in z
2379-
x in y
2380-
x in z
2381-
[builtins fixtures/primitives.pyi]
2382-
2383-
[case testEnableBytearrayMemoryviewPromotionStrictEquality]
2384-
# flags: --strict-equality
2371+
# flags: --strict-equality --strict-bytes
23852372
def f(x: bytes, y: bytearray, z: memoryview) -> None:
23862373
x == y
23872374
y == z

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

+2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ f(1)
2222
[builtins fixtures/primitives.pyi]
2323

2424
[case testPromoteBytearrayToByte]
25+
# flags: --no-strict-bytes
2526
def f(x: bytes) -> None: pass
2627
f(bytearray(b''))
2728
[builtins fixtures/primitives.pyi]
2829

2930
[case testPromoteMemoryviewToBytes]
31+
# flags: --no-strict-bytes
3032
def f(x: bytes) -> None: pass
3133
f(memoryview(b''))
3234
[builtins fixtures/primitives.pyi]

0 commit comments

Comments
 (0)