From 96b4330ef9dd7cea4441d9d7c538a9d9dadc985c Mon Sep 17 00:00:00 2001 From: Laurent Soest Date: Sat, 28 Aug 2021 20:43:04 +0200 Subject: [PATCH 1/4] testing: added test to override generator with annotation --- test/completion/generators.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/completion/generators.py b/test/completion/generators.py index 798398cf..3b04d932 100644 --- a/test/completion/generators.py +++ b/test/completion/generators.py @@ -309,3 +309,8 @@ def annotation2() -> Iterator[float]: next(annotation1()) #? float() next(annotation2()) + + +# annotations should override generator inference +#? float() +annotation1() From fe50352f9cb3b6bbb1abd4243e257c3863c36af3 Mon Sep 17 00:00:00 2001 From: Laurent Soest Date: Sat, 28 Aug 2021 20:53:54 +0200 Subject: [PATCH 2/4] annotations should be preferred even when it is a generator --- jedi/inference/value/function.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jedi/inference/value/function.py b/jedi/inference/value/function.py index 2471a065..a89e9c88 100644 --- a/jedi/inference/value/function.py +++ b/jedi/inference/value/function.py @@ -344,7 +344,8 @@ class BaseFunctionExecutionContext(ValueContext, TreeContextMixin): GenericClass(c, TupleGenericManager(generics)) for c in async_classes ).execute_annotation() else: - if self.is_generator(): + # If there are annotations, prefer them over anything else. + if self.is_generator() and not self.infer_annotations(): return ValueSet([iterable.Generator(inference_state, self)]) else: return self.get_return_values() From 8808b5b64b06260aa9b98231ea0b52408114f8b5 Mon Sep 17 00:00:00 2001 From: boerde Date: Sun, 29 Aug 2021 00:38:34 +0200 Subject: [PATCH 3/4] added test to override fixture return value with annotation --- test/completion/pytest.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/completion/pytest.py b/test/completion/pytest.py index f49fd921..3c648c6c 100644 --- a/test/completion/pytest.py +++ b/test/completion/pytest.py @@ -64,6 +64,11 @@ def lala(my_fixture): def lala(my_fixture): pass +# overriding types of a fixture should be possible +def test_x(my_yield_fixture: str): + #? str() + my_yield_fixture + # ----------------- # completion # ----------------- From 3cf98f6ba1af21eb04c67a2025f56edd46ab7deb Mon Sep 17 00:00:00 2001 From: boerde Date: Sun, 29 Aug 2021 09:17:04 +0200 Subject: [PATCH 4/4] paramters with annotation do not need special pytest handling --- jedi/plugins/pytest.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/jedi/plugins/pytest.py b/jedi/plugins/pytest.py index 56bf9ce9..0e196c72 100644 --- a/jedi/plugins/pytest.py +++ b/jedi/plugins/pytest.py @@ -43,6 +43,9 @@ def infer_anonymous_param(func): return function_context.get_return_values() def wrapper(param_name): + # parameters with an annotation do not need special handling + if param_name.annotation_node: + return func(param_name) is_pytest_param, param_name_is_function_name = \ _is_a_pytest_param_and_inherited(param_name) if is_pytest_param: