Skip to content

narrow on initial assignment #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3082,7 +3082,9 @@ def visit_assignment_stmt(self, s: AssignmentStmt) -> None:
# as X | Y.
if not (s.is_alias_def and self.is_stub):
with self.enter_final_context(s.is_final_def):
self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
self.check_assignment(
s.lvalues[-1], s.rvalue, infer_lvalue_type=True, new_syntax=s.new_syntax
)

if s.is_alias_def:
self.check_type_alias_rvalue(s)
Expand Down Expand Up @@ -3110,7 +3112,7 @@ def visit_assignment_stmt(self, s: AssignmentStmt) -> None:
rvalue = self.temp_node(self.lookup_type(s.rvalue), s)
for lv in s.lvalues[:-1]:
with self.enter_final_context(s.is_final_def):
self.check_assignment(lv, rvalue, s.type is None)
self.check_assignment(lv, rvalue, infer_lvalue_type=True)

self.check_final(s)
if (
Expand Down
1 change: 0 additions & 1 deletion mypy/plugins/attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,6 @@ def _parse_converter(
converter_info.init_type = AnyType(TypeOfAny.from_error)
return converter_info

converter_type = get_proper_type(converter_type)
if isinstance(converter_type, CallableType) and converter_type.arg_types:
converter_info.init_type = converter_type.arg_types[0]
if not is_attr_converters_optional:
Expand Down
2 changes: 1 addition & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6770,7 +6770,7 @@ def _get_node_for_class_scoped_import(
# mypyc is absolutely convinced that `symbol_node` narrows to a Var in the following,
# when it can also be a FuncBase. Once fixed, `f` in the following can be removed.
# See also https://github.com/mypyc/mypyc/issues/892
f: Callable[[object], Any] = lambda x: x
f = cast(Callable[[object], Any], lambda x: x)
if isinstance(f(symbol_node), (Decorator, FuncBase, Var)):
# For imports in class scope, we construct a new node to represent the symbol and
# set its `info` attribute to `self.type`.
Expand Down
9 changes: 2 additions & 7 deletions mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2185,7 +2185,8 @@ def with_normalized_var_args(self) -> Self:
types_suffix = self.arg_types[var_arg_index + 1 :]
kinds_suffix = self.arg_kinds[var_arg_index + 1 :]
names_suffix = self.arg_names[var_arg_index + 1 :]
no_name: str | None = None # to silence mypy
names_middle: list[str | None]
no_name = cast("str | None", None)

# Now we have something non-trivial to do.
if unpack_index is None:
Expand Down Expand Up @@ -3731,12 +3732,6 @@ def find_unpack_in_list(items: Sequence[Type]) -> int | None:
unpack_index: int | None = None
for i, item in enumerate(items):
if isinstance(item, UnpackType):
# We cannot fail here, so we must check this in an earlier
# semanal phase.
# Funky code here avoids mypyc narrowing the type of unpack_index.
old_index = unpack_index
assert old_index is None
# Don't return so that we can also sanity check there is only one.
unpack_index = i
return unpack_index

Expand Down
Loading