From c9f33f274b9b0efecccaed160bd8ce664b227cdc Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Sun, 18 Aug 2019 20:57:13 +0100 Subject: [PATCH] Enable TypedDict vs overload interaction that was disabled --- mypy/checkexpr.py | 4 +--- test-data/unit/check-overloading.test | 6 ++---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index 772da98bfbc3..9f141f0d8591 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -1437,9 +1437,7 @@ def plausible_overload_call_targets(self, order.""" def has_shape(typ: Type) -> bool: - # TODO: Once https://github.com/python/mypy/issues/5198 is fixed, - # add 'isinstance(typ, TypedDictType)' somewhere below. - return (isinstance(typ, TupleType) + return (isinstance(typ, TupleType) or isinstance(typ, TypedDictType) or (isinstance(typ, Instance) and typ.type.is_named_tuple)) matches = [] # type: List[CallableType] diff --git a/test-data/unit/check-overloading.test b/test-data/unit/check-overloading.test index a7bea55c28f3..f08d0bd22d61 100644 --- a/test-data/unit/check-overloading.test +++ b/test-data/unit/check-overloading.test @@ -2551,11 +2551,9 @@ reveal_type(f(**{'x': 4, 'y': 4})) # N: Revealed type is 'builtins.tup reveal_type(f(**{'a': 4, 'b': 4, 'c': 4})) # N: Revealed type is 'builtins.tuple[builtins.int]' [builtins fixtures/dict.pyi] -[case testOverloadKwargsSelectionWithTypedDict-skip] -# TODO: Mypy doesn't seem to correctly destructure typed dicts in general. -# We should re-enable this once https://github.com/python/mypy/issues/5198 is resolved +[case testOverloadKwargsSelectionWithTypedDict] from typing import overload, Tuple -from mypy_extensions import TypedDict +from typing_extensions import TypedDict @overload def f(*, x: int) -> Tuple[int]: ... @overload