3 ms·
This article mentions the woes of circular imports. I thought MyPy let you work around that by doing if False: around your imports eg a.py: import c if Fa
by daniel_rh 4y ago
This article mentions the woes of circular imports.
I thought MyPy let you work around that by doing if False: around your imports
eg
a.py:
import c
if False:
import b
class X:
def x(self):
#type: () -> b.Y
from b import something_that_returns_y
return something_that_returns_y(self)
b.py:
from a import X
class Y:
pass
def something_that_returns_y(x : X) -> Y:
return Y()
per https://github.com/asottile/flake8-typing-imports https://github.com/asottile/flake8-typing-imports
- blibble 4y agothat's pretty horrible a few more things like that and it will start to look like machine generated javascript
- charliermarsh 4y agoYeah that's correct! It's a valid workaround, and we end up doing that occasionally. (In Python 3.5 and newer it's `if TYPE_CHECKING` instead of `if False`.)