Skip to content

Remove use of join during semantic analysis #3320

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

Merged
merged 1 commit into from
May 4, 2017
Merged
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
9 changes: 6 additions & 3 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2048,9 +2048,12 @@ def build_namedtuple_typeinfo(self, name: str, items: List[str], types: List[Typ
# Actual signature should return OrderedDict[str, Union[types]]
ordereddictype = (self.named_type_or_none('builtins.dict', [strtype, AnyType()])
or self.object_type())
# 'builtins.tuple' has only one type parameter, the corresponding type argument
# in the fallback instance is a join of all item types.
fallback = self.named_type('__builtins__.tuple', [join.join_type_list(types)])
# 'builtins.tuple' has only one type parameter.
#
# TODO: The corresponding type argument in the fallback instance should be a join of
# all item types, but we can't do joins during this pass of semantic analysis
# and we are using Any as a workaround.
fallback = self.named_type('__builtins__.tuple', [AnyType()])
# Note: actual signature should accept an invariant version of Iterable[UnionType[types]].
# but it can't be expressed. 'new' and 'len' should be callable types.
iterable_type = self.named_type_or_none('typing.Iterable', [AnyType()])
Expand Down
10 changes: 10 additions & 0 deletions test-data/unit/check-namedtuple.test
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,13 @@ def f(x: a.X) -> None:
[out]
tmp/b.py:6: error: Revealed type is 'a.X'
tmp/b.py:8: error: Revealed type is 'Tuple[Any, fallback=a.X]'

[case testForwardReferenceInNamedTuple]
from typing import NamedTuple

class A(NamedTuple):
b: 'B'
x: int

class B:
pass