Repository navigation
Commit 8d104f8
fix(semantics): let a module-scope import alias take the name it rebinds
``action = "run"`` followed by ``import os as action`` left the scan
reporting ``values=['run'], unresolved=false`` while CPython bound the
module object. The gate that reads this treats a resolved set as stronger
evidence than unknown, so the shape produced false certainty rather than a
missed value.
The cause was one set answering two questions. At module scope an import is
how a producer names the owner module it qualifies against, so an import
there must not shadow that qualified binding -- which is why ``imported``
was left empty for ``<module>``. The same set was then reused for
``rebound_by_other_forms``, the check that asks whether a later binding
takes the name away from a plain assignment. Skipping module scope for the
first question silently skipped it for the second, and the superseded
literal survived as a complete set.
The two questions are now asked of two sets. ``import_bound`` collects the
names every import binds, in every scope, and feeds the rebinding check;
``imported`` stays empty at module scope and keeps feeding the shadow set,
so owner-module qualification is untouched. A name has to be both plainly
assigned and import-bound in the same scope for this to change anything,
which is exactly the counterexample and nothing else.
``MODULE_ASSIGNED_THEN_IMPORTED`` adds the module-scope variant to the
executable property test, which runs the snippet under CPython and compares
what it observes against what the scan reports. It fails on the previous
code with the module repr the scan omitted, and passes here.
Nothing on the tracked tree carries the shape: the drift smoke reports the
same unresolved_producer_sites=40 and the same blocker distribution
(annotation_only=5, argument_name_only=10, attribute_read=7, call_result=14,
other=1, unstable_local=3) as before the fix. ``tests/architecture`` 684
passed. Ruff reports the same four findings as main at lines this change
does not touch, and ``git diff --check`` is clean.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: song <22676124+songoow@users.noreply.github.com>1 parent 1751f98 commit 8d104f8
2 files changed
Lines changed: 30 additions & 6 deletions
File tree
- loopx/semantics
- tests/architecture
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
470 | 470 | | |
471 | 471 | | |
472 | 472 | | |
473 | | - | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
478 | 486 | | |
479 | 487 | | |
480 | 488 | | |
| |||
509 | 517 | | |
510 | 518 | | |
511 | 519 | | |
512 | | - | |
| 520 | + | |
513 | 521 | | |
514 | 522 | | |
515 | 523 | | |
| |||
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
100 | 115 | | |
101 | 116 | | |
102 | 117 | | |
| |||
155 | 170 | | |
156 | 171 | | |
157 | 172 | | |
| 173 | + | |
158 | 174 | | |
159 | 175 | | |
160 | 176 | | |
| |||
0 commit comments