Support passing values through decorators from factories

This builds on the approach taken in https://github.com/davidhalter/jedi/pull/1613
but applies it to type vars themselves so that their type var
nature is preserved when a function returns Callable[[T], T] and
the T has an upper bound.
This commit is contained in:
Peter Law
2020-06-14 18:17:09 +01:00
parent 2d0258db1a
commit 5184d0cb9c
3 changed files with 59 additions and 3 deletions

View File

@@ -250,6 +250,28 @@ is_decorated_by_class_decorator_factory(the_par
)
def decorator_factory_plain() -> Callable[[T], T]:
pass
#? Callable()
decorator_factory_plain()
#?
decorator_factory_plain()()
#? int()
decorator_factory_plain()(42)
is_decorated_by_plain_factory = decorator_factory_plain()(will_be_decorated)
#? will_be_decorated
is_decorated_by_plain_factory
#? ['the_param=']
is_decorated_by_plain_factory(the_par
)
class class_decorator_factory_bound_callable:
def __call__(self, func: TCallable) -> TCallable:
...
@@ -270,6 +292,25 @@ is_decorated_by_class_bound_factory(the_par
)
def decorator_factory_bound_callable() -> Callable[[TCallable], TCallable]:
pass
#? Callable()
decorator_factory_bound_callable()
#? Callable()
decorator_factory_bound_callable()()
is_decorated_by_bound_factory = decorator_factory_bound_callable()(will_be_decorated)
#? will_be_decorated
is_decorated_by_bound_factory
#? ['the_param=']
is_decorated_by_bound_factory(the_par
)
class That(Generic[T]):
def __init__(self, items: List[Tuple[str, T]]) -> None:
pass