modules-as-protocols triggers "no-redef" when using import-imports, but is fine with from-imports
(I'm testing out this unreleased feature on the primary branch)
# main.pyimportosfromtypingimportProtocolclassP(Protocol):
deff(self) ->str: ...
t: Pifos.environ.get('ENV') =='prod':
importtast# Name "t" already defined on line 7 [no-redef]else:
importuast# Name "t" already defined on line 7 [no-redef]
# t.py and u.pydeff() ->str:
return''
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):
mkdir y
touch y/__init__.py
mv {t,u}.py y
importosfromtypingimportProtocolclassP(Protocol):
deff(self) ->str: ...
t: Pifos.environ.get('ENV') =='prod':
fromyimporttast# no errors!else:
fromyimportuast# no errors!
Your Environment
Mypy version used: mypy 0.990+dev.dc5c299aa190949f2300b163ccc10257a779006d (compiled: no)
Mypy command-line flags: none
Mypy configuration options from mypy.ini (and other config files): none
Activity
hauntsaninja commented on Oct 4, 2022
Thanks for the report!
Note mainly for self: looks like the difference is between add_symbol_table_node
mypy/mypy/semanal.py
Line 5457 in ddd9177
and process_imported_symbol
mypy/mypy/semanal.py
Line 2309 in ddd9177
Better story for import redefinitions
Better story for import redefinitions (#13969)
hauntsaninja commented on Nov 3, 2022
Thanks for reporting! This should now be fixed on master, but isn't part of the 0.990 release.