◐ Shell
reader mode source ↗
Skip to content

Provide detailed error for circular from imports#5972

Merged
youknowone merged 5 commits into
RustPython:mainfrom
ever0de:fix/circular-import-error
Jul 14, 2025
Merged

Provide detailed error for circular from imports#5972
youknowone merged 5 commits into
RustPython:mainfrom
ever0de:fix/circular-import-error

Conversation

@ever0de

@ever0de ever0de commented Jul 14, 2025

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes

    • Improved error messages when importing names from a module, providing clearer information in cases of circular imports or partial initialization.
  • New Features

    • Enhanced detection of modules that are still initializing, helping users identify circular import issues more easily.

@coderabbitai

coderabbitai Bot commented Jul 14, 2025

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@ever0de has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 6 minutes and 36 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 9d6912c and 69c0294.

📒 Files selected for processing (1)
  • vm/src/frame.rs (2 hunks)

Walkthrough

The import_from method in the ExecutingFrame struct was revised to improve error handling and fallback logic during module imports. A new helper function, is_module_initializing, was introduced to check if a module is still initializing, allowing for more precise import error messages, especially in cases of circular imports or partial initialization.

Changes

File(s) Change Summary
vm/src/frame.rs Refactored import_from to improve fallback logic and error reporting; added is_module_initializing helper function.

Poem

In the warren of code, a module peeks through,
Importing its friends, as rabbits often do.
If caught in a loop, or half-awake yawn,
A new error message hops helpfully on.
With clearer advice, imports now sing—
No more confusion in the Python spring! 🐇

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ever0de ever0de force-pushed the fix/circular-import-error branch 2 times, most recently from 9c09aef to dfb4db1 Compare July 14, 2025 15:04
@ever0de ever0de force-pushed the fix/circular-import-error branch from dfb4db1 to d86644e Compare July 14, 2025 15:07
@ever0de ever0de changed the title fix(vm): provide detailed error for circular from imports Jul 14, 2025
@ever0de ever0de marked this pull request as ready for review July 14, 2025 15:22

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hide comment

Actionable comments posted: 2

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fd35c7a and d86644e.

⛔ Files ignored due to path filters (1)
  • Lib/test/test_import/__init__.py is excluded by !Lib/**
📒 Files selected for processing (3)
  • vm/src/builtins/module.rs (3 hunks)
  • vm/src/frame.rs (2 hunks)
  • vm/src/import.rs (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .github/copilot-instructions.md
🧠 Learnings (2)
vm/src/builtins/module.rs (1)
Learnt from: CR
PR: RustPython/RustPython#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-06-30T10:08:48.858Z
Learning: Applies to **/*.rs : Use the macro system (`pyclass`, `pymodule`, `pyfunction`, etc.) when implementing Python functionality in Rust
vm/src/import.rs (1)
Learnt from: CR
PR: RustPython/RustPython#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-06-30T10:08:48.858Z
Learning: Applies to **/*.rs : Use the macro system (`pyclass`, `pymodule`, `pyfunction`, etc.) when implementing Python functionality in Rust
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Run snippets and cpython tests (windows-latest)
🔇 Additional comments (4)
vm/src/builtins/module.rs (2)

1-1: LGTM! Atomic boolean field properly added for initialization tracking.

The AtomicBool import and field addition are appropriate for tracking module initialization state in a thread-safe manner.

Also applies to: 57-57


80-80: Field initialization is correct in both constructors.

The initializing field is properly initialized to false in both new() and from_def() constructors, ensuring modules start in a non-initializing state.

Also applies to: 88-88

vm/src/import.rs (2)

3-3: Imports correctly added for atomic operations.

The Ordering import and PyModule addition are necessary for the initialization tracking implementation.

Also applies to: 7-7


161-178: Well-implemented guard pattern for initialization tracking.

The guard ensures the initializing flag is always reset, even if module code execution fails or panics. The use of Ordering::Relaxed is appropriate here.

However, this sets an internal field that isn't exposed to Python code. The frame.rs code checks __spec__._initializing, which is a different attribute. Consider exposing this state to Python.

@ever0de

ever0de commented Jul 14, 2025

Copy link
Copy Markdown
Contributor Author

@ever0de ever0de force-pushed the fix/circular-import-error branch from 2d99040 to 69c0294 Compare July 14, 2025 16:09

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hide comment

nice feature! Thanks!

Hide details View details @youknowone youknowone merged commit d4f85cf into RustPython:main Jul 14, 2025
12 checks passed
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