Skip to content

Preserve user wrapper frames when inferring resource anchors - #338

Open
kokotatan wants to merge 1 commit into
python:mainfrom
kokotatan:fix-inferred-wrapper-caller
Open

kokotatan wants to merge 1 commit into
python:mainfrom
kokotatan:fix-inferred-wrapper-caller

Conversation

@kokotatan

Copy link
Copy Markdown

When files() is called without an anchor inside a user-defined function named wrapper, caller inference skips that function as though it were functools.singledispatch internals. A call from another module consequently searches that other module's resources and can raise FileNotFoundError even though the resource exists beside the actual caller.

Restrict the wrapper exclusion to frames belonging to functools. This preserves the documented caller-module behavior, including when importlib_resources has been compiled without its sources.

The four new regression cases exercise disk and ZIP packages with both ordinary and compiled-only importlib_resources. All four fail on the original code and pass with the fix. The existing caller-inference tests continue to pass.

Validation on Windows / Python 3.12.10:

  • test_files.py: 29 passed.
  • Full tox -e py312: 302 passed, 1 skipped, 11 failures. The unchanged 1d55475 checkout reproduces the same 11 failures: 10 existing file-level Ruff checks and the _path.build doctest requiring Windows symlink privileges. Baseline result: 298 passed, 1 skipped.
  • Functional run with the known failing helper doctest and lint/type plugins excluded: 219 passed, 1 skipped.
  • Mypy: all 30 source files pass; tox -e docs: Sphinx and SphinxLint pass.
  • Changed-line coverage: 100% of 9 executable lines.

AI assistance: implemented and tested using Codex, with independent read-only review using Claude Opus. The related source-free caller-inference fix in #314 remains covered by the existing and new tests.

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