Resolve relative imports by their level (#369); accept complete enum-literal unions (upstream a490662) - #416
Closed
Wamwea wants to merge 3 commits into
Closed
Conversation
…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.
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.
TLDR
Fixes relative-import resolution (
from ..sub import modno longer false-positivesimports_unresolved, Refs #369) and teachesassignment_compatibilitythe 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 afrom-import, populated fromStmtImportFrom.levelin the visitor (class_info_ext.rs) for both named and star forms; always0for 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.assignment_compatibility(rules/assignment_compatibility/mod.rs):SkipNames.enum_members,collect_enum_members(members = valued class-body attributes, excludingnonmember(...)and_-prefixed names), andenum_complete_union_assignableimplementing the typing-spec enums rule "a complete union of all literal members is equivalent to the enum type".crates/basilisk-checker/tests/relative_import_resolution_tests.rs— 8 tests driving parse → visitor →resolve_module_importsover the issue Relative "from ..mylib.some import smth" was broken several versions ago #369 package layout.crates/basilisk-checker/tests/checker/assignment_compatibility_2_tests.rs— 5 tests for the enum complete-union equivalence.What Was Changed or Deleted?
resolve_module_imports(crates/basilisk-checker/src/imports/apply.rs) now dispatches imports withrelative_level > 0to the relative resolver instead of the absolute search path. Previously the level was discarded, sofrom ..sub import modwas resolved as absolutesuband failed; single-dot imports only worked by accident via the importer-directory fallback.subis not installed" help text is gone.check_varsinassignment_compatibilityaccepts an enum-typed value assigned to aLiteral[...]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 againstmain— upstream's own committed results graded basilisk (and mypy, and pyright) as failing the newenums_expansion.pytest4.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, anddouble_dot_star_import_resolves_to_parent_sibling_packageall failed withresolution == Unresolvedbefore the fix and now assert the exact resolved paths (src/pkg/sub/__init__.py,src/pkg/sub/mod.py, …). Guardssingle_dot_sibling_module_resolves,missing_relative_target_stays_unresolved, andabsolute_import_still_walks_search_pathspin 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, andnonmember_attribute_does_not_count_toward_completenessfailed before the fix;enum_assigned_to_incomplete_literal_union_firesandliteral_union_of_wrong_enum_still_firesprove incomplete/wrong unions still error.python/typingharness (fresh clone ofa490662, unmodifiedsrc/main.py --only-run basilisk, clean release build): 141/141 graded files pass, 0 false positives — including the broadenedenums_expansion.py. Without the enum fix the gate fails at 99% with 1 FP.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 thecheck_varschange is killed by the new tests).Spec / Doc Changes
README/README.zh/README-pypi,
docs/readme/*sources,docs/specs/CHECKER-ARCHITECTURE-SPEC.md, andwebsite/src/_data/conformance_report.jsoncarry only the regenerated conformance stamps (graded commit0dc9b5d→a490662), produced by the scorer's own stamping pass.Breaking Changes
🤖 Generated with Claude Code