Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,12 @@ def add_invertible_flag(
parser.add_argument(
"--enable-incomplete-features", action="store_true", help=argparse.SUPPRESS
)
parser.add_argument(
"--_disable-bytearray-promotion", action="store_true", help=argparse.SUPPRESS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we don't need the underscore if we're already suppressing the flag.

)
parser.add_argument(
"--_disable-memoryview-promotion", action="store_true", help=argparse.SUPPRESS
)

# options specifying code to check
code_group = parser.add_argument_group(
Expand Down
16 changes: 13 additions & 3 deletions mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,16 @@ class BuildType:
"warn_unused_ignores",
}

OPTIONS_AFFECTING_CACHE: Final = (PER_MODULE_OPTIONS | {"platform", "bazel", "plugins"}) - {
"debug_cache"
}
OPTIONS_AFFECTING_CACHE: Final = (
PER_MODULE_OPTIONS
| {
"platform",
"bazel",
"plugins",
"_disable_bytearray_promotion",
"_disable_memoryview_promotion",
}
) - {"debug_cache"}

# Features that are currently incomplete/experimental
TYPE_VAR_TUPLE: Final = "TypeVarTuple"
Expand Down Expand Up @@ -329,6 +336,9 @@ def __init__(self) -> None:
# Deprecated reverse version of the above, do not use.
self.enable_recursive_aliases = False

self._disable_bytearray_promotion = False
self._disable_memoryview_promotion = False

# To avoid breaking plugin compatibility, keep providing new_semantic_analyzer
@property
def new_semantic_analyzer(self) -> bool:
Expand Down
10 changes: 10 additions & 0 deletions mypy/semanal_classprop.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ def add_type_promotion(
if not promote_targets:
if defn.fullname in TYPE_PROMOTIONS:
target_sym = module_names.get(TYPE_PROMOTIONS[defn.fullname])
if (
defn.fullname == "builtins.bytearray"
and options._disable_bytearray_promotion
):
target_sym = None
elif (
defn.fullname == "builtins.memoryview"
and options._disable_memoryview_promotion
):
target_sym = None
# With test stubs, the target may not exist.
if target_sym:
target_info = target_sym.node
Expand Down