Skip to content

Circular imports? #346

Answered by klmr
dereckmezquita asked this question in Q&A
Oct 27, 2023 · 1 comments · 4 replies
Discussion options

You must be logged in to vote

Hi @dereckmezquita, yes, that’s one of the limitations of circular modules: you cannot use any imported name while the module is still in a partial loading state. The lines some_module <- something_from_main * 2 and print(some_module) are potentially problematic because they are attempting to use an imported name while the module the name is coming from is still being loaded.

The easiest way of dealing with circular imports is to break the circle. In your example you could do this by putting something_from_main into a third module, which you then import in both main and module.

However, you can use circular imports here, if you avoid that some_module is used during the (circular) import of

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@dereckmezquita
Comment options

@klmr
Comment options

klmr Oct 30, 2023
Maintainer

Answer selected by dereckmezquita
@klmr
Comment options

klmr Oct 30, 2023
Maintainer

@dereckmezquita
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants