mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
Merge pull request #1826 from PeterJCLaw/fix-1801-typed-decorator-on-instance-method
Make typed decorators work for instance methods
This commit is contained in:
@@ -294,6 +294,9 @@ class Callable(BaseTypingInstance):
|
|||||||
from jedi.inference.gradual.annotation import infer_return_for_callable
|
from jedi.inference.gradual.annotation import infer_return_for_callable
|
||||||
return infer_return_for_callable(arguments, param_values, result_values)
|
return infer_return_for_callable(arguments, param_values, result_values)
|
||||||
|
|
||||||
|
def py__get__(self, instance, class_value):
|
||||||
|
return ValueSet([self])
|
||||||
|
|
||||||
|
|
||||||
class Tuple(BaseTypingInstance):
|
class Tuple(BaseTypingInstance):
|
||||||
def _is_homogenous(self):
|
def _is_homogenous(self):
|
||||||
|
|||||||
@@ -110,4 +110,4 @@ class Test(object):
|
|||||||
# nocond lambdas make no sense at all.
|
# nocond lambdas make no sense at all.
|
||||||
|
|
||||||
#? int()
|
#? int()
|
||||||
[a for a in [1,2] if lambda: 3][0]
|
[a for a in [1,2] if (lambda: 3)][0]
|
||||||
|
|||||||
50
test/completion/pep0484_decorators.py
Normal file
50
test/completion/pep0484_decorators.py
Normal file
@@ -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()
|
||||||
Reference in New Issue
Block a user