Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
Update more
  • Loading branch information
JukkaL committed Apr 20, 2026
commit 1c4a3ffbf95bff85593fd9ed6e200f3d45a31e27
4 changes: 2 additions & 2 deletions mypy/binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def __init__(self, options: Options) -> None:

# If True, initial assignment to a simple variable (e.g. "x", but not "x.y")
# is added to the binder. This allows more precise narrowing and more
# flexible inference of variable types (--allow-redefinition-new).
# flexible inference of variable types (--allow-redefinition).
self.bind_all = options.allow_redefinition

# This tracks any externally visible changes in binder to invalidate
Expand Down Expand Up @@ -339,7 +339,7 @@ def update_from_options(self, frames: list[Frame]) -> bool:
continue

# Remove exact duplicates to save pointless work later, this is
# a micro-optimization for --allow-redefinition-new.
# a micro-optimization for --allow-redefinition.
seen_types = set()
resulting_types = []
for rv in resulting_values:
Expand Down
6 changes: 3 additions & 3 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4607,7 +4607,7 @@ def infer_partial_type(self, name: Var, lvalue: Lvalue, init_type: Type) -> bool
if isinstance(init_type, NoneType) and (
isinstance(lvalue, MemberExpr) or not self.options.allow_redefinition
):
# When using --allow-redefinition-new, None types aren't special
# When using --allow-redefinition, None types aren't special
# when inferring simple variable types.
partial_type = PartialType(None, name)
elif isinstance(init_type, Instance):
Expand Down Expand Up @@ -4855,7 +4855,7 @@ def check_simple_assignment(
get_proper_type(lvalue_type), AnyType
)

# If redefinitions are allowed (i.e. we have --allow-redefinition-new
# If redefinitions are allowed (i.e. we have --allow-redefinition
# and a variable without annotation) or if a variable has union type we
# try inferring r.h.s. twice with a fallback type context. The only exception
# is TypedDicts, they are often useless without context.
Expand Down Expand Up @@ -5025,7 +5025,7 @@ def replace_partial_type(
self.binder.version += 1
del partial_types[var]
if self.options.allow_redefinition:
# When using --allow-redefinition-new, binder tracks all types of
# When using --allow-redefinition, binder tracks all types of
# simple variables.
n = NameExpr(var.name)
n.node = var
Expand Down
6 changes: 3 additions & 3 deletions mypy/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,9 @@ def parse_section(
# Here we use `key` for original config section key, and `options_key` for
# the corresponding Options attribute.
options_key = key
# Match aliasing for command line flag.
if key.endswith("allow_redefinition"):
options_key += "_old"
# Match aliasing for deprecated config option name.
if options_key == "allow_redefinition_new":
options_key = "allow_redefinition"
if key in config_types:
ct = config_types[key]
elif key in invalid_options:
Expand Down
10 changes: 5 additions & 5 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ def main(

if options.allow_redefinition and not options.local_partial_types:
fail(
"error: --local-partial-types must be enabled if using --allow-redefinition-new",
"error: --local-partial-types must be enabled if using --allow-redefinition",
stderr,
options,
)

if options.allow_redefinition and options.allow_redefinition_old:
fail(
"--allow-redefinition-old and --allow-redefinition-new should not be used together",
"--allow-redefinition-old and --allow-redefinition should not be used together",
stderr,
options,
)
Expand Down Expand Up @@ -888,9 +888,8 @@ def add_invertible_flag(
"--allow-redefinition",
default=False,
strict_flag=False,
help="Alias to --allow-redefinition-old; will point to --allow-redefinition-new in v2.0",
help="Allow flexible variable redefinition with a new type",
group=strictness_group,
dest="allow_redefinition_old",
)

add_invertible_flag(
Expand All @@ -905,8 +904,9 @@ def add_invertible_flag(
"--allow-redefinition-new",
default=False,
strict_flag=False,
help="Allow more flexible variable redefinition semantics",
help="Deprecated alias for --allow-redefinition",
group=strictness_group,
dest="allow_redefinition",
)

add_invertible_flag(
Expand Down
2 changes: 1 addition & 1 deletion mypy/nativeparse.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# mypy: allow-redefinition-new, local-partial-types
# mypy: allow-redefinition, local-partial-types
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These are actually both enabled in self-check, so this is a no-op.

"""Python parser that directly constructs a native AST (when compiled).
Use a Rust extension to generate a serialized AST, and deserialize the AST directly
Expand Down
7 changes: 3 additions & 4 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,16 +712,15 @@ def refresh_top_level(self, file_node: MypyFile) -> None:
n.column = 0
n.end_line = 1
n.end_column = 0
self.fail("--local-partial-types must be enabled if using --allow-redefinition-new", n)
self.fail("--local-partial-types must be enabled if using --allow-redefinition", n)
if self.options.allow_redefinition and self.options.allow_redefinition_old:
n = TempNode(AnyType(TypeOfAny.special_form))
n.line = 1
n.column = 0
n.end_line = 1
n.end_column = 0
self.fail(
"--allow-redefinition-old and --allow-redefinition-new"
" should not be used together",
"--allow-redefinition-old and --allow-redefinition should not be used together",
n,
)
self.recurse_into_functions = False
Expand Down Expand Up @@ -4495,7 +4494,7 @@ def analyze_name_lvalue(
if self.is_func_scope():
if unmangle(name) == "_" and not self.options.allow_redefinition:
# Special case for assignment to local named '_': always infer 'Any'.
# This isn't needed with --allow-redefinition-new, since arbitrary
# This isn't needed with --allow-redefinition, since arbitrary
# types can be assigned to '_' anyway.
typ = AnyType(TypeOfAny.special_form)
self.store_declared_types(lvalue, typ)
Expand Down