Skip to content
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

Fix namedtuple crash in unannotated function #12804

Merged
merged 3 commits into from May 18, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions mypy/semanal_namedtuple.py
Expand Up @@ -186,6 +186,8 @@ def check_namedtuple(self,
# Error. Construct dummy return value.
if var_name:
name = var_name
if is_func_scope:
name += '@' + str(call.line)
else:
name = 'namedtuple@' + str(call.line)
info = self.build_namedtuple_typeinfo(name, [], [], {}, node.line)
Expand Down
21 changes: 21 additions & 0 deletions test-data/unit/check-incremental.test
Expand Up @@ -5711,3 +5711,24 @@ class C:
[builtins fixtures/dict.pyi]
[out2]
tmp/a.py:2: error: "object" has no attribute "xyz"

[case testIncrementalInvalidNamedTupleInUnannotatedFunction]
import a

[file a.py]
import b

[file a.py.2]
import b # f

[file b.py]
from typing import NamedTuple

def crash(fields):
TupleType = NamedTuple("TupleType", fields)
class InheritFromTuple(TupleType):
pass
NT2 = NamedTuple("bad", [('x', int)])
nt2: NT2 = NT2(x=1)

[builtins fixtures/tuple.pyi]