Skip to content

Commit 51f80f8

Browse files
authored
support for strict_bytes in stubtest (#19002)
I confirmed that this fixes #18744
1 parent 7f5a8dd commit 51f80f8

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

mypy/main.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,9 +1449,7 @@ def set_strict_flags() -> None:
14491449
process_cache_map(parser, special_opts, options)
14501450

14511451
# Process --strict-bytes
1452-
if options.strict_bytes:
1453-
options.disable_bytearray_promotion = True
1454-
options.disable_memoryview_promotion = True
1452+
options.process_strict_bytes()
14551453

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

mypy/options.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,16 @@ def process_incomplete_features(
466466
if feature in COMPLETE_FEATURES:
467467
warning_callback(f"Warning: {feature} is already enabled by default")
468468

469+
def process_strict_bytes(self) -> None:
470+
# Sync `--strict-bytes` and `--disable-{bytearray,memoryview}-promotion`
471+
if self.strict_bytes:
472+
# backwards compatibility
473+
self.disable_bytearray_promotion = True
474+
self.disable_memoryview_promotion = True
475+
elif self.disable_bytearray_promotion and self.disable_memoryview_promotion:
476+
# forwards compatibility
477+
self.strict_bytes = True
478+
469479
def apply_changes(self, changes: dict[str, object]) -> Options:
470480
# Note: effects of this method *must* be idempotent.
471481
new_options = Options()

mypy/stubtest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,6 +2003,7 @@ def warning_callback(msg: str) -> None:
20032003
options.process_incomplete_features(
20042004
error_callback=error_callback, warning_callback=warning_callback
20052005
)
2006+
options.process_strict_bytes()
20062007

20072008
try:
20082009
modules = build_stubs(modules, options, find_submodules=not args.check_typeshed)

0 commit comments

Comments
 (0)