Skip to content

Resolve relative imports by their level (#369); accept complete enum-literal unions (upstream a490662) - #416

Closed
Wamwea wants to merge 3 commits into
Nimblesite:mainfrom
Wamwea:fix/relative-import-resolution-369
Closed

Resolve relative imports by their level (#369); accept complete enum-literal unions (upstream a490662)#416
Wamwea wants to merge 3 commits into
Nimblesite:mainfrom
Wamwea:fix/relative-import-resolution-369

Conversation

@Wamwea

@Wamwea Wamwea commented Aug 5, 2026

Copy link
Copy Markdown

TLDR

Fixes relative-import resolution (from ..sub import mod no longer false-positives imports_unresolved, Refs #369) and teaches assignment_compatibility the enums-expansion equivalence that python/typing@a490662 now requires, keeping conformance at 141/141 (100%) with 0 false positives.

What Was Added?

  • ImportInfo.relative_level: u32 (crates/basilisk-resolver/src/scope/import_types.rs) — the leading-dot count of a from-import, populated from StmtImportFrom.level in the visitor (class_info_ext.rs) for both named and star forms; always 0 for plain imports.
  • resolve_relative_import_cached (crates/basilisk-checker/src/imports/resolve.rs) — FsCache-aware variant of the existing (previously dead) relative resolver, so the per-file import loop shares directory listings.
  • Enum-member knowledge in assignment_compatibility (rules/assignment_compatibility/mod.rs): SkipNames.enum_members, collect_enum_members (members = valued class-body attributes, excluding nonmember(...) and _-prefixed names), and enum_complete_union_assignable implementing the typing-spec enums rule "a complete union of all literal members is equivalent to the enum type".
  • New integration tests:

What Was Changed or Deleted?

  • resolve_module_imports (crates/basilisk-checker/src/imports/apply.rs) now dispatches imports with relative_level > 0 to the relative resolver instead of the absolute search path. Previously the level was discarded, so from ..sub import mod was resolved as absolute sub and failed; single-dot imports only worked by accident via the importer-directory fallback.
  • Relative imports are exempted from uv-registry classification, package-metadata enrichment, and typeshed stub-distribution lookup — a relative import can never be a PyPI package, so the misleading "sub is not installed" help text is gone.
  • check_vars in assignment_compatibility accepts an enum-typed value assigned to a Literal[...] union naming every member of that enum (incomplete unions and other enums' members still mismatch). This closes the false positive that python/typing@a490662 ("Conformance: broaden enum-expansion tests", merged 2026-08-04) introduced against main — upstream's own committed results graded basilisk (and mypy, and pyright) as failing the new enums_expansion.py test4.
  • Generated/ratcheted artifacts from the gates: conformance stamps re-graded at a490662 (READMEs, docs/specs/CHECKER-ARCHITECTURE-SPEC.md, website/src/_data/conformance_report.json), and the mutation baseline ratchets up (138/145 → 139/146 caught, kill rate 100%).

How Do The Automated Tests Prove It Works?

  • relative_import_resolution_tests.rs: double_dot_bare_module_target_resolves_to_parent_sibling_package, double_dot_dotted_module_target_resolves_through_parent_package, bare_dot_import_resolves_to_own_package_init, bare_double_dot_import_resolves_to_parent_package_init, and double_dot_star_import_resolves_to_parent_sibling_package all failed with resolution == Unresolved before the fix and now assert the exact resolved paths (src/pkg/sub/__init__.py, src/pkg/sub/mod.py, …). Guards single_dot_sibling_module_resolves, missing_relative_target_stays_unresolved, and absolute_import_still_walks_search_paths pin that the dispatch neither breaks the accidental single-dot path nor blanket-accepts unresolvable or absolute imports.
  • assignment_compatibility_2_tests.rs: enum_assigned_to_complete_literal_union_no_diagnostic, single_member_enum_assigned_to_its_literal_no_diagnostic, and nonmember_attribute_does_not_count_toward_completeness failed before the fix; enum_assigned_to_incomplete_literal_union_fires and literal_union_of_wrong_enum_still_fires prove incomplete/wrong unions still error.
  • The real python/typing harness (fresh clone of a490662, unmodified src/main.py --only-run basilisk, clean release build): 141/141 graded files pass, 0 false positives — including the broadened enums_expansion.py. Without the enum fix the gate fails at 99% with 1 FP.
  • Full local CI-equivalent run: workspace tests + coverage (all 8 crate thresholds met), make lint, Zed (97 tests + standalone mirror build), VS Code e2e (633 tests + corpus suites), Neovim suite (44.13% ≥ 44%), Shipwright binary gate, website build + 52 Playwright tests, and mutation testing (146 mutants, 139 caught, 0 missed, 100% kill rate — the one new mutant introduced by the check_vars change is killed by the new tests).

Spec / Doc Changes

README/README.zh/README-pypi, docs/readme/* sources, docs/specs/CHECKER-ARCHITECTURE-SPEC.md, and website/src/_data/conformance_report.json carry only the regenerated conformance stamps (graded commit 0dc9b5da490662), produced by the scorer's own stamping pass.

Breaking Changes

  • None

🤖 Generated with Claude Code

Wamwea and others added 3 commits August 5, 2026 15:01
…num-literal unions per upstream a490662

Relative from-imports (from ..sub import mod, from . import x) were resolved
as absolute module names: StmtImportFrom.level was dropped when building
ImportInfo, and resolve_relative_import was never called from the pipeline.
Carry the level through ImportInfo, dispatch nonzero-level imports to the
relative resolver in resolve_module_imports, and exempt relative imports
from uv-registry classification and typeshed distribution lookup.

Also teach assignment_compatibility the enums-expansion equivalence (a
complete union of all literal members is equivalent to the enum type),
required by python/typing@a490662's broadened enums_expansion test; the
conformance gate holds at 141/141 (100%) with 0 false positives.

Mutation baseline ratchets up to 139/146 caught (100% kill rate);
conformance references re-stamp to the newly graded upstream commit.

Refs Nimblesite#369
…um fix duplicated by upstream

Upstream Nimblesite#413 independently shipped the enum literal-expansion equivalence
(assignment_compatibility/enum_expand.rs, GitHub Nimblesite#374), so this branch's
duplicate implementation and its two overlapping tests are dropped in favor
of upstream's; the three edge-case tests upstream lacks (single-member enum,
nonmember() attributes, wrong-enum union) are kept. Mutation baseline
resolves to upstream's wider 154/161 pool pending a fresh run on the merged
tree.
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