mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 05:54:25 +08:00
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.
51 lines
651 B
Python
51 lines
651 B
Python
""" 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()
|