Skip to content

Use TypedDict fallback as its suggestion representation #7606

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
Oct 2, 2019
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
4 changes: 4 additions & 0 deletions mypy/suggestions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
TypeVarType, FunctionLike,
TypeStrVisitor, TypeTranslator,
is_optional, remove_optional, ProperType, get_proper_type,
TypedDictType
)
from mypy.build import State, Graph
from mypy.nodes import (
Expand Down Expand Up @@ -711,6 +712,9 @@ def visit_tuple_type(self, t: TupleType) -> str:
s = self.list_str(t.items)
return 'Tuple[{}]'.format(s)

def visit_typeddict_type(self, t: TypedDictType) -> str:
return t.fallback.accept(self)

def visit_union_type(self, t: UnionType) -> str:
if len(t.items) == 2 and is_optional(t):
return "Optional[{}]".format(remove_optional(t).accept(self))
Expand Down
14 changes: 14 additions & 0 deletions test-data/unit/fine-grained-suggest.test
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,20 @@ def foo():
() -> foo.N
==

[case testSuggestInferTypedDict]
# suggest: foo.foo
[file foo.py]
from typing_extensions import TypedDict
TD = TypedDict('TD', {'x': int})
def foo():
return bar()

def bar() -> TD: ...
[builtins fixtures/dict.pyi]
[out]
() -> foo.TD
==

[case testSuggestReexportNaming]
# suggest: foo.foo
[file foo.py]
Expand Down
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