Skip to content
Closed
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
17 changes: 12 additions & 5 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2878,11 +2878,18 @@ def analyze_name_lvalue(self,
lvalue.fullname = var._fullname
else:
lvalue.fullname = lvalue.name
if self.is_func_scope():
if unmangle(name) == '_':
# Special case for assignment to local named '_': always infer 'Any'.
typ = AnyType(TypeOfAny.special_form)
self.store_declared_types(lvalue, typ)

# Special case for assignment to local named '_': always infer 'Any'.
is_special_unused = self.is_func_scope() and unmangle(name) == '_'

# Special case, `Any` is defined as `= object()` in typeshed,
# so we need to make it a real type variable.
is_typing_any = var.fullname == 'typing.Any'

if is_special_unused or is_typing_any:
typ = AnyType(TypeOfAny.special_form)
self.store_declared_types(lvalue, typ)

if is_final and self.is_final_redefinition(kind, name):
self.fail("Cannot redefine an existing name as final", lvalue)
else:
Expand Down