Circular Imports
Talk it through out loud with your AI coach.
The problem
- medium
- Pro
Your orders module imports a function from your customers module, and customers imports a class from orders. Now the app fails at start-up with an error saying it cannot import a name from a partially initialised module. Explain what's happening and how you'd fix it.
What a strong answer covers
- How Python records and runs a module during import.
- Why the second import sees an unfinished module.
- The design change that removes the cycle.
- Quicker workarounds and when they're acceptable.
Common mistake: Shuffling import lines around until it happens to work, without fixing the dependency between the two modules.
Knowing this is half of it. Saying it clearly out loud is the part the coach helps you practise.
Practise it out loud