Make sure Callable TypeVars are better identified, solves a part of #1413

This commit is contained in:
Dave Halter
2019-12-07 15:01:47 +01:00
parent 4bd7c2e627
commit ab8f0ba834
2 changed files with 20 additions and 0 deletions

View File

@@ -315,6 +315,17 @@ def _infer_type_vars(annotation_value, value_set, is_class_value=False):
is_class_value=True,
)
)
elif name == 'Callable':
given = annotation_value.get_generics()
if len(given) == 2:
for nested_annotation_value in given[1]:
_merge_type_var_dicts(
type_var_dict,
_infer_type_vars(
nested_annotation_value,
value_set.execute_annotation(),
)
)
elif isinstance(annotation_value, LazyGenericClass):
name = annotation_value.py__name__()
if name == 'Iterable':

View File

@@ -402,6 +402,15 @@ type_in_out2()
#? float()
type_in_out2(float)
def ma(a: typing.Callable[[str], TYPE_VARX]) -> typing.Callable[[str], TYPE_VARX]:
return a
def mf(s: str) -> int:
return int(s)
#? int()
ma(mf)('2')
# -------------------------
# TYPE_CHECKING
# -------------------------