-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better types for modules #3500
Comments
IIRC you get an error "Name 'mod1' already defined" on the second. The
solution is to put a `# type: ignore` there, then mypy will assume the type
of the first import. Honestly that seems reasonable to me.
But if you really want the Module[] notation, the argument should probably
the full module name, not the filename, i.e. Union[Module['fastmath'],
Module['math']].
|
Actually mypy assumes the type of the (textually) last encountered import
Except that there is a dozen issues on the tracker about
I am more interested in having a better internal handling of modules first. Having something conceptually equivalent to "a union of symbol tables" would solve many of the existing issues. Then, depending on experience we could consider adding syntactic support for such types. |
OK, you're right.
|
Resolves #3494 (Since module types are tracked in #3500) Following #8187 (comment) and #3494, if I understand correctly and the semantics in #3494's example code has been fixed (report error on re-assign Alias = B, the remaining work of #3494 is to update the docs, which is the main focus of this PR. Newly added docs are in common issues and solutions section, with the content mostly adapted from Ivan's example in #3494. And a note point to the docs is also added.
In situations with dynamically/conditionally imported modules:
mypy can infer only
types.ModuleType
for themod1
node. Another (quite widespread) example is something like:In such case all symbol table information for
math
andfastmath
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 offastmath
would beUnion[Module['/path/to/fastmath'], Module['math']]
. Then mypy will be able to inferfastmath.sin
asCallable[[float], float]
.The text was updated successfully, but these errors were encountered: