Skip to content

parser(python): imports of a module with a .pyi beside it resolve to the .py - #1878

Merged
swapnilpaliwal-sd merged 1 commit into
apps/integration-0.1.9from
fix/parser-py-module-prefers-source
Oct 10, 2026
Merged

swapnilpaliwal-sd merged 1 commit into
apps/integration-0.1.9from
fix/parser-py-module-prefers-source

Conversation

@swapnilpaliwal-sd

Copy link
Copy Markdown
Contributor

Symptom. In a Python package that ships .pyi stubs beside its .py modules, impact / --tests on a function in the package returned no tests: every call into the package ended at the library boundary.

Cause. The parser's project linker keys modules by qualified name. impl.py and impl.pyi share one, the later file wins, and .pyi sorts after .py, so imports resolved to the stub. The engine correctly never makes a stub declaration an edge target.

Fix. A stub does not replace a non-stub module of the same name; a stub-only module is still resolved. Parser package stays 0.2.0.

Evidence (16 public Python repositories, mutation oracle, base = current integration branch):

base fix
test-selection recall (all 16) 0.540 0.554
every failing test file selected 43.6% 51.0%
empty answers 24.3% 17.1%

Two repositories ship stubs this way: recall 0.015 → 0.985 and 0.512 → 0.604 (precision 0.629 → 0.582 on the second, source-caller recall 0.610 → 0.636). The other 14 are unchanged on every metric. Parser Python suite 23/23; query cases python 308/308; Python engine suite 43/43, torture unchanged. New case stub-beside-source-resolves-to-source fails on the base parser and passes here, with a control that the stub is never an edge target.

…it resolves to the .py

The project linker keys modules by qualified name, and a package that ships `impl.pyi`
beside `impl.py` declares that name twice. The later file won the map, and `.pyi` sorts
after `.py`, so `from .impl import *` and `import pkg` resolved to the stub. The engine
refuses a stub declaration as an edge target, so every call into such a package ended at
the library boundary and its tests reached nothing in it.

A stub no longer replaces a non-stub module of the same name. A stub with no `.py` beside
it is still the import's target.

Co-authored-by: axiomcode-bot[bot] <334110751+axiomcode-bot[bot]@users.noreply.github.com>
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.

1 participant