Skip to content

Preserve package imports whose names match builtins - #2121

Closed
FanWu-ai wants to merge 1 commit into
davidhalter:masterfrom
FanWu-ai:fix-package-builtin-module-resolution-oct13
Closed

FanWu-ai wants to merge 1 commit into
davidhalter:masterfrom
FanWu-ai:fix-package-builtin-module-resolution-oct13

Conversation

@FanWu-ai

Copy link
Copy Markdown

Fixes #2019.

When resolving localpackage._ast, the builtin importer receives the leaf name _ast and ignores the package search path. It claims the top-level builtin before the path finder can find the real package module, so inference and goto return no definition. Skip the builtin importer for package searches while retaining its precedence for top-level imports.

Eight regression cases cover _ast and sys, ordinary modules and packages, and absolute and relative imports. They check inference, goto, completion, and unchanged top-level builtin resolution. All eight fail against the original source and pass with this change.

One existing namespace test now explicitly uses its temporary directory as the Project root. This makes it independent of a Git checkout above the temporary directory; its assertions are unchanged. The original source with only that fixture adjustment passes the complete suite (4,014 tests).

Validation on Linux / CPython 3.12.14:

  • Complete suite, interpreter mode: 4,022 passed, 23 skipped, 5 xfailed.
  • Complete suite, subprocess mode and coverage run: 4,024 passed, 21 skipped, 5 xfailed.
  • Repository Flake8 and Zuban checks pass.
  • Sphinx HTML build with warnings as errors, wheel/sdist builds, and diff whitespace checks pass.

The skips/xfails are existing repository markers. Optional strict Twine warns about the existing missing description-content-type metadata; the separately enabled, normally unconfigured Sphinx doctest builder has the same 17 failures on original and patched code. Neither is presented as a passing required check. Other platforms and Python versions were not validated as a full matrix.

Prepared with OpenAI Codex assistance.

@FanWu-ai
FanWu-ai marked this pull request as ready for review October 12, 2026 21:58
@FanWu-ai
FanWu-ai deleted the fix-package-builtin-module-resolution-oct13 branch October 13, 2026 05:45
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.

name conflict with builtin modules

2 participants