Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix import loop (circular import) #3282

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

davidculley
Copy link
Contributor

I wanted to write an unit test but couldn't because I encountered an import loop (meaning: before you can finish importing A you must import B, but you can import B only after you finished importing A, so the import fails because it would result in an infinite loop).

This pull request fixed that problem.

Here's an explainer of the problem and why this pull request is necessary:
https://www.youtube.com/watch?v=UnKa_t-M_kM

@dae
Copy link
Member

dae commented Jul 21, 2024

The fact that it doesn't work out of the box is unfortunate. It used to - this broke when pylib switched to an implicit namespace, which means we can't run any code when the base module is imported. A simple workaround is for calling code to import anki.collection first. The other imports should then import correctly.

I'm not sure about this PR. Importing a submodule as a separate symbol is not something our codebase currently typically does, and having to prefix types like NoteId is not ideal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants