Make it possible to infer Callable TypeVars, fixes #1449

This commit is contained in:
Dave Halter
2019-12-12 23:22:52 +01:00
parent 536a77551b
commit e656a5f18f
6 changed files with 101 additions and 5 deletions

View File

@@ -216,8 +216,19 @@ class TypeAlias(LazyValueWrapper):
class Callable(BaseTypingValueWithGenerics):
def py__call__(self, arguments):
"""
def x() -> Callable[[Callable[..., _T]], _T]: ...
"""
# The 0th index are the arguments.
return self._generics_manager.get_index_and_execute(1)
try:
param_values = self._generics_manager[0]
result_values = self._generics_manager[1]
except IndexError:
debug.warning('Callable[...] defined without two arguments')
return NO_VALUES
else:
from jedi.inference.gradual.annotation import infer_return_for_callable
return infer_return_for_callable(arguments, param_values, result_values)
class Tuple(LazyValueWrapper):