From 72cf41f4c905b493d8044da976302c731bd068bf Mon Sep 17 00:00:00 2001 From: Peter Law Date: Sun, 12 Dec 2021 18:16:46 +0000 Subject: [PATCH 1/2] Lambdas in comprehensions need parentheses in Python > 3.8 Fixes https://github.com/davidhalter/jedi/issues/1824. --- test/completion/lambdas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/completion/lambdas.py b/test/completion/lambdas.py index 524df0ce..54821c9d 100644 --- a/test/completion/lambdas.py +++ b/test/completion/lambdas.py @@ -110,4 +110,4 @@ class Test(object): # nocond lambdas make no sense at all. #? int() -[a for a in [1,2] if lambda: 3][0] +[a for a in [1,2] if (lambda: 3)][0] From b6f761f13c5e26f7976920f3d925b81777eb7b8f Mon Sep 17 00:00:00 2001 From: Peter Law Date: Sun, 12 Dec 2021 17:36:53 +0000 Subject: [PATCH 2/2] Make typed decorators work for instance methods This feels incomplete when compared to FunctionMixin.py__get__, however seems to work at least in the cut-down reported. Fixes https://github.com/davidhalter/jedi/issues/1801. --- jedi/inference/gradual/typing.py | 3 ++ test/completion/pep0484_decorators.py | 50 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 test/completion/pep0484_decorators.py diff --git a/jedi/inference/gradual/typing.py b/jedi/inference/gradual/typing.py index c2f08a33..188d3270 100644 --- a/jedi/inference/gradual/typing.py +++ b/jedi/inference/gradual/typing.py @@ -294,6 +294,9 @@ class Callable(BaseTypingInstance): from jedi.inference.gradual.annotation import infer_return_for_callable return infer_return_for_callable(arguments, param_values, result_values) + def py__get__(self, instance, class_value): + return ValueSet([self]) + class Tuple(BaseTypingInstance): def _is_homogenous(self): diff --git a/test/completion/pep0484_decorators.py b/test/completion/pep0484_decorators.py new file mode 100644 index 00000000..ea3add02 --- /dev/null +++ b/test/completion/pep0484_decorators.py @@ -0,0 +1,50 @@ +""" Pep-0484 type hinted decorators """ + +from typing import Callable + + +def decorator(func): + def wrapper(*a, **k): + return str(func(*a, **k)) + return wrapper + + +def typed_decorator(func: Callable[..., int]) -> Callable[..., str]: + ... + +# Functions + +@decorator +def plain_func() -> int: + return 4 + +#? str() +plain_func() + + +@typed_decorator +def typed_func() -> int: + return 4 + +#? str() +typed_func() + + +# Methods + +class X: + @decorator + def plain_method(self) -> int: + return 4 + + @typed_decorator + def typed_method(self) -> int: + return 4 + +inst = X() + +#? str() +inst.plain_method() + +#? str() +inst.typed_method()