Skip to content

Commit 6c4599d

Browse files
ilevkivskyimsullivan
authored andcommitted
Use TypedDict fallback as its suggestion representation (python#7606)
1 parent bfa3c84 commit 6c4599d

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

mypy/suggestions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
TypeVarType, FunctionLike,
3434
TypeStrVisitor, TypeTranslator,
3535
is_optional, remove_optional, ProperType, get_proper_type,
36+
TypedDictType
3637
)
3738
from mypy.build import State, Graph
3839
from mypy.nodes import (
@@ -711,6 +712,9 @@ def visit_tuple_type(self, t: TupleType) -> str:
711712
s = self.list_str(t.items)
712713
return 'Tuple[{}]'.format(s)
713714

715+
def visit_typeddict_type(self, t: TypedDictType) -> str:
716+
return t.fallback.accept(self)
717+
714718
def visit_union_type(self, t: UnionType) -> str:
715719
if len(t.items) == 2 and is_optional(t):
716720
return "Optional[{}]".format(remove_optional(t).accept(self))

test-data/unit/fine-grained-suggest.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,20 @@ def foo():
139139
() -> foo.N
140140
==
141141

142+
[case testSuggestInferTypedDict]
143+
# suggest: foo.foo
144+
[file foo.py]
145+
from typing_extensions import TypedDict
146+
TD = TypedDict('TD', {'x': int})
147+
def foo():
148+
return bar()
149+
150+
def bar() -> TD: ...
151+
[builtins fixtures/dict.pyi]
152+
[out]
153+
() -> foo.TD
154+
==
155+
142156
[case testSuggestReexportNaming]
143157
# suggest: foo.foo
144158
[file foo.py]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy