Skip to content
Merged
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
4 changes: 1 addition & 3 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1449,9 +1449,7 @@ def set_strict_flags() -> None:
process_cache_map(parser, special_opts, options)

# Process --strict-bytes
if options.strict_bytes:
options.disable_bytearray_promotion = True
options.disable_memoryview_promotion = True
options.process_strict_bytes()

# An explicitly specified cache_fine_grained implies local_partial_types
# (because otherwise the cache is not compatible with dmypy)
Expand Down
10 changes: 10 additions & 0 deletions mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,16 @@ def process_incomplete_features(
if feature in COMPLETE_FEATURES:
warning_callback(f"Warning: {feature} is already enabled by default")

def process_strict_bytes(self) -> None:
# Sync `--strict-bytes` and `--disable-{bytearray,memoryview}-promotion`
if self.strict_bytes:
# backwards compatibility
self.disable_bytearray_promotion = True
self.disable_memoryview_promotion = True
elif self.disable_bytearray_promotion and self.disable_memoryview_promotion:
# forwards compatibility
self.strict_bytes = True

def apply_changes(self, changes: dict[str, object]) -> Options:
# Note: effects of this method *must* be idempotent.
new_options = Options()
Expand Down
1 change: 1 addition & 0 deletions mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2003,6 +2003,7 @@ def warning_callback(msg: str) -> None:
options.process_incomplete_features(
error_callback=error_callback, warning_callback=warning_callback
)
options.process_strict_bytes()

try:
modules = build_stubs(modules, options, find_submodules=not args.check_typeshed)
Expand Down