Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Does this fix the circular imports problem that comes up if you don't structural your programs in a hierarchical way?


This is what I thought of too. I really only know python, do other languages not have that issue? In python it does not seem like a "problem" to me - whenever I have seen circular import issues it is because the code is organized poorly. I worry that this feature will lead to devs "fixing" circular import issues by using lazy imports.


Sometimes it's hard to avoid cyclic imports, without blaming the design. Like if a Parent has a Child, and the Child needs to know of the parent. Only way to solve that in python is to put everything in the same file, which also feels like bad deisgn.


I would say in that case, the Parent and Child shouldn't need to know about each other - some kind of handler in a different file should.

Although I guess that doesn't work in all cases, like defining foreign key relationships when using an orm (like sqlalchemy) for example. But in the orm case, the way to get around that is... lazy resolution :^)


Interesting. I find that I always have this problem in any non-trivial python project, and don't find this to be due to poorly organized code. I have only seen this requirement in Python.

IME circular import errors aren't due to poor organization; they're due to an arbitrary restriction Python has.


Even with eager importing there is only a "circular import problem" if you try to import names `from` the modules — as I pointed out a few days ago (https://news.ycombinator.com/item?id=45400783).


It should, when you do lazy imports on your own it fixes the problem.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: