diff --git a/mypy/main.py b/mypy/main.py index 4d9cec63bbc19..9ea189f675ebc 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -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) diff --git a/mypy/options.py b/mypy/options.py index c086dfc8aea36..52afd27211ed0 100644 --- a/mypy/options.py +++ b/mypy/options.py @@ -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() diff --git a/mypy/stubtest.py b/mypy/stubtest.py index ab29d9dca4b83..6c90913885c93 100644 --- a/mypy/stubtest.py +++ b/mypy/stubtest.py @@ -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)