Sample code for: Python Circular Imports: Why They Happen and How to Fix Them - #830
Open
stephengruppetta wants to merge 1 commit into
Open
stephengruppetta wants to merge 1 commit into
stephengruppetta wants to merge 1 commit into
Conversation
…Fix Them Seven self-contained projects, one per stage of the tutorial. Each has the same shop/ package plus a main.py, so a reader can run any stage without editing files in place. Two of them fail on purpose: broken/ is the circular import the tutorial sets out to fix, and workaround3_attribute_error/ shows the module-level attribute access failing. Verified on CPython 3.14.6. Passes ruff format and ruff check under the repo config, with two noqa directives where the tutorial is deliberately showing code a linter objects to. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sample code for Python Circular Imports: Why They Happen and How to Fix Them (CMS Post 2247).
Seven self-contained projects, one per stage of the tutorial. Each carries the same
shop/package plus amain.py, so a reader can run any stage without editing files in place.broken/ImportError(on purpose)step1_remove_dependency/2004.99on 3.14,NameErroron 3.13 and earlierstep2_guard_annotation/2004.99workaround1_defer_import/1004.99workaround2_bottom_import/1004.99workaround3_attribute_error/AttributeError(on purpose)workaround3_import_module/1004.99All seven verified on CPython 3.14.6. Passes
ruff format --checkandruff checkunder the repo config.Two
# noqadirectives, both where the tutorial is deliberately showing code a linter objects to:F821instep1_remove_dependency/(the annotation is unresolvable until Step 2 guards the import) andE402inworkaround2_bottom_import/(the bottom import is the technique being demonstrated). Both are explained in the folder README.🤖 Generated with Claude Code