Hacker News new | ask | show | jobs
by daniel_rh 1397 days 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
2 comments

Yeah 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`.)
that's pretty horrible

a few more things like that and it will start to look like machine generated javascript