From 85f45771f1cec080dc7c28390c405795ef02d3d9 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 1 Jan 2021 04:22:52 +0100 Subject: [PATCH] Fix typing.NewType signature --- jedi/inference/gradual/typing.py | 13 ++++++------- test/test_inference/test_signature.py | 4 ++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/jedi/inference/gradual/typing.py b/jedi/inference/gradual/typing.py index 414338e8..23fb9a42 100644 --- a/jedi/inference/gradual/typing.py +++ b/jedi/inference/gradual/typing.py @@ -76,8 +76,8 @@ class TypingModuleName(NameWrapper): yield OverloadFunction.create_cached( inference_state, self.parent_context, self.tree_name) elif name == 'NewType': - yield NewTypeFunction.create_cached( - inference_state, self.parent_context, self.tree_name) + v, = self._wrapped_name.infer() + yield NewTypeFunction.create_cached(inference_state, v) elif name == 'cast': cast_fn, = self._wrapped_name.infer() yield CastFunction.create_cached(inference_state, cast_fn) @@ -86,11 +86,10 @@ class TypingModuleName(NameWrapper): # added soon. yield TypedDictClass.create_cached( inference_state, self.parent_context, self.tree_name) - elif name in ('no_type_check', 'no_type_check_decorator'): - # This is not necessary, as long as we are not doing type checking. - yield from self._wrapped_name.infer() else: - # Everything else shouldn't be relevant for type checking. + # Not necessary, as long as we are not doing type checking: + # no_type_check & no_type_check_decorator + # Everything else shouldn't be relevant... yield from self._wrapped_name.infer() @@ -398,7 +397,7 @@ class OverloadFunction(BaseTypingValue): return func_value_set -class NewTypeFunction(BaseTypingValue): +class NewTypeFunction(ValueWrapper): def py__call__(self, arguments): ordered_args = arguments.unpack() next(ordered_args, (None, None)) diff --git a/test/test_inference/test_signature.py b/test/test_inference/test_signature.py index 49e9894e..85adaff7 100644 --- a/test/test_inference/test_signature.py +++ b/test/test_inference/test_signature.py @@ -117,6 +117,10 @@ class X: ('from typing import List\nList[int](', None), ('from typing import Tuple\nTuple(', None), ('from typing import Tuple\nTuple[int](', None), + ('from typing import Optional\nOptional(', None), + ('from typing import Optional\nOptional[int](', None), + ('from typing import Any\nAny(', None), + ('from typing import NewType\nNewType(', 'NewType(name: str, tp: Type[_T]) -> Type[_T]'), ] ) def test_tree_signature(Script, environment, code, expected):