Fixed bug in callable type narrowing logic where the union of the type includes None.

This commit is contained in:
Eric Traut 2020-09-28 07:26:49 -07:00
parent 8c01e0d652
commit 9a991dc8d3
2 changed files with 7 additions and 1 deletions

View File

@ -12660,6 +12660,7 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
return isPositiveTest ? subtype : undefined;
}
case TypeCategory.None:
case TypeCategory.Module: {
return isPositiveTest ? undefined : subtype;
}

View File

@ -1,7 +1,7 @@
# This sample tests the type engine's narrowing logic for
# callable expressions.
from typing import Callable, Type, Union
from typing import Callable, Optional, Type, Union
class CallableObj:
@ -29,3 +29,8 @@ if callable(q):
if not callable(q):
a = q + 3
def g(a: Optional[Callable[[int], int]]):
if callable(a):
a(3)