mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
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.
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):
|
||||||
|
|||||||
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