You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from __future__ importannotationsfromtypingimportTYPE_CHECKINGifTYPE_CHECKING:
fromSandpitimportfoodefasdf() ->foo: # or Module[foo]fromSandpitimportfooreturnfoo
Pitch
this pattern is useful as a quick hack for resolving circular imports, also pycharm allows it
The text was updated successfully, but these errors were encountered:
I don't think modules should be allowed in the type system. The semantics of a module type are not well defined.
PEP 544 provides a potential solution here. It allows a protocol to describe a module's interface. This is how this would be solved in other languages like TypeScript.
It looks like mypy doesn't support this part of PEP 544 though. See this issue for details.
The other solution, of course, is to eliminate the circular dependency in your code. ;)
I think in the past people have used types.ModuleType then used hasattr etc. But I would agree that modules as types are tricky, and I think #5018 is a better solution.
Feature
Pitch
this pattern is useful as a quick hack for resolving circular imports, also pycharm allows it
The text was updated successfully, but these errors were encountered: