Skip to content
Draft
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
2 changes: 1 addition & 1 deletion mypy/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
from mypy_extensions import u8

# High-level cache layout format
CACHE_VERSION: Final = 5
CACHE_VERSION: Final = 6

# Type used internally to represent errors:
# (path, line, column, end_line, end_column, severity, message, code)
Expand Down
2 changes: 1 addition & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4421,7 +4421,7 @@ def check_lvalue(
if (
self.options.allow_redefinition_new
and isinstance(lvalue.node, Var)
and lvalue.node.is_inferred
and (lvalue.node.is_inferred or lvalue.node.is_argument)
):
inferred = lvalue.node
self.store_type(lvalue, lvalue_type)
Expand Down
1 change: 1 addition & 0 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,7 @@ def make_argument(

var = Var(arg.arg, arg_type)
var.is_inferred = False
var.is_argument = True
argument = Argument(var, arg_type, self.visit(default), kind, pos_only)
argument.set_line(arg.lineno, arg.col_offset, arg.end_lineno, arg.end_col_offset)
return argument
Expand Down
12 changes: 4 additions & 8 deletions mypy/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,7 @@ class Var(SymbolNode):
"has_explicit_value",
"allow_incompatible_override",
"invalid_partial_type",
"is_argument",
)

__match_args__ = ("name", "type", "final_value")
Expand Down Expand Up @@ -1351,6 +1352,8 @@ def __init__(self, name: str, type: mypy.types.Type | None = None) -> None:
# If True, this means we didn't manage to infer full type and fall back to
# something like list[Any]. We may decide to not use such types as context.
self.invalid_partial_type = False
# Is it a variable symbol for a function argument?
self.is_argument = False

@property
def name(self) -> str:
Expand Down Expand Up @@ -1414,8 +1417,6 @@ def write(self, data: WriteBuffer) -> None:
write_flags(
data,
[
self.is_self,
self.is_cls,
self.is_initialized_in_class,
self.is_staticmethod,
self.is_classmethod,
Expand Down Expand Up @@ -1453,8 +1454,6 @@ def read(cls, data: ReadBuffer) -> Var:
v.setter_type = setter_type
v._fullname = read_str(data)
(
v.is_self,
v.is_cls,
v.is_initialized_in_class,
v.is_staticmethod,
v.is_classmethod,
Expand All @@ -1474,7 +1473,7 @@ def read(cls, data: ReadBuffer) -> Var:
v.from_module_getattr,
v.has_explicit_value,
v.allow_incompatible_override,
) = read_flags(data, num_flags=21)
) = read_flags(data, num_flags=19)
tag = read_tag(data)
if tag == LITERAL_COMPLEX:
v.final_value = complex(read_float_bare(data), read_float_bare(data))
Expand Down Expand Up @@ -2368,9 +2367,6 @@ def __init__(
analyzed: Expression | None = None,
) -> None:
super().__init__()
if not arg_names:
arg_names = [None] * len(args)

self.callee = callee
self.args = args
self.arg_kinds = arg_kinds # ARG_ constants
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-redefine2.test
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,8 @@ def f2() -> None:
def f3(x) -> None:
if int():
x = 0
reveal_type(x) # N: Revealed type is "Any"
reveal_type(x) # N: Revealed type is "Any"
reveal_type(x) # N: Revealed type is "builtins.int"
reveal_type(x) # N: Revealed type is "Any | builtins.int"

[case tetNewRedefineDel]
# flags: --allow-redefinition-new --local-partial-types
Expand Down