-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
no-redef
when import
-importing a module to satisfy a protocol
#13803
Labels
Comments
Thanks for the report! Note mainly for self: looks like the difference is between Line 5457 in ddd9177
and process_imported_symbol Line 2309 in ddd9177
process_import_over_existing_name isn't called for normal imports, but just changing that should probably fix
|
hauntsaninja
added a commit
to hauntsaninja/mypy
that referenced
this issue
Oct 31, 2022
This changes our importing logic to be more consistent and to treat import statements more like assignments. Fixes python#13803 The primary motivation for this is when typing modules as protocols, as in the linked issue. But it turns out we already allowed redefinition with from imports, so this just seems like a nice consistency win. We move shared logic from visit_import_all and visit_import_from (via process_imported_symbol) into add_imported_symbol. We then reuse it in visit_import. To simplify stuff, we inline the code from add_module_symbol into visit_import. Then we copy over logic from add_symbol, because MypyFile is not a SymbolTableNode, but this isn't the worst thing ever. Finally, we now need to check non-from import statements like assignments, which was a thing we weren't doing earlier.
hauntsaninja
added a commit
that referenced
this issue
Nov 3, 2022
This changes our importing logic to be more consistent and to treat import statements more like assignments. Fixes #13803, fixes #13914, fixes half of #12965, probably fixes #12574 The primary motivation for this is when typing modules as protocols, as in #13803. But it turns out we already allowed redefinition with "from" imports, so this also seems like a nice consistency win. We move shared logic from visit_import_all and visit_import_from (via process_imported_symbol) into add_imported_symbol. We then reuse it in visit_import. To simplify stuff, we inline the code from add_module_symbol into visit_import. Then we copy over logic from add_symbol, because MypyFile is not a SymbolTableNode, but this isn't the worst thing ever. Finally, we now need to check non-from import statements like assignments, which was a thing we weren't doing earlier.
Thanks for reporting! This should now be fixed on master, but isn't part of the 0.990 release. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug Report
modules-as-protocols triggers "no-redef" when using
import
-imports, but is fine withfrom
-imports(I'm testing out this unreleased feature on the primary branch)
the errors triggered are inline above
oddly enough, a
from
import seems to work fine (so there's an easy workaround if the module isn't top-level):Your Environment
mypy 0.990+dev.dc5c299aa190949f2300b163ccc10257a779006d (compiled: no)
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: