-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Description
In situations with dynamically/conditionally imported modules:
if random() > 0.5:
import mod1
else:
import mod2 as mod1
mypy can infer only types.ModuleType
for the mod1
node. Another (quite widespread) example is something like:
try:
import fastmath
except ImportError:
import math as fastmath
In such case all symbol table information for math
and fastmath
is "lost". We could support (at least internally) some special type that will hold symbol table information and will be allowed to appear in unions (or support structural joins). For example, in the above case type of fastmath
would be Union[Module['/path/to/fastmath'], Module['math']]
. Then mypy will be able to infer fastmath.sin
as Callable[[float], float]
.