Skip to content

Fix Python submodule import ordering#165

Merged
hardbyte merged 3 commits into
mainfrom
fix-python-submodule-import-order
Jun 3, 2026
Merged

Fix Python submodule import ordering#165
hardbyte merged 3 commits into
mainfrom
fix-python-submodule-import-order

Conversation

@hardbyte
Copy link
Copy Markdown
Contributor

@hardbyte hardbyte commented Jun 3, 2026

Summary

  • order generated Python package submodule imports by sibling namespace references so Python 3.14/Pydantic can import dependent sibling modules
  • keep stable import order for cyclic sibling references that still rely on deferred rebuild handling
  • fix Rust codegen snapshot stub typechecking on macOS by using the host proc-macro library suffix
  • add regression coverage and changelog notes

Fixes #164

Testing

  • cargo fmt --check
  • git diff --check
  • cargo test -p reflectapi
  • cargo test -p reflectapi-demo
  • PYTHONPATH=reflectapi-demo/target/codegen-coverage-client uv run --python 3.14 --project reflectapi-python-runtime python -c 'import codegen_coverage_client; from codegen_coverage_client import _rebuild; _rebuild.rebuild_models(); print("python 3.14 import/rebuild ok")'

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a060f8fbd3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread reflectapi/src/codegen/python.rs Outdated
Comment on lines +2448 to +2451
let mut sibling_path = ns_path.to_vec();
sibling_path.push(sibling_name.clone());
let sibling_qualified_name = module_qualified_name(&sibling_path);
if contains_qualified_name(&rendered_code, &sibling_qualified_name) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid matching nested namespaces as root siblings

When ordering root-level packages (ns_path is empty), sibling_qualified_name is just the bare root name, so contains_qualified_name also matches nested references like x.common.Type because the preceding . is treated as a boundary. If there is also a real top-level common package and it depends on x, this false x -> common edge creates a cycle and the code falls back to the original/alphabetical order, leaving common imported before its real dependency x and reintroducing the import-time failure this change is meant to prevent. Root sibling detection needs to distinguish common.Type from suffixes such as x.common.Type.

Useful? React with 👍 / 👎.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

📖 Documentation Preview: https://reflectapi-docs-preview-pr-165.partly.workers.dev

Updated automatically from commit e995249

@hardbyte hardbyte merged commit 44a4765 into main Jun 3, 2026
6 checks passed
@hardbyte hardbyte deleted the fix-python-submodule-import-order branch June 3, 2026 03:41
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.

Python codegen: emit submodule import order topologically for Python 3.14 / PEP 649

1 participant