Skip to content

Skip type-hint resolution for noninjectable parameters - #330

Open
edsonsims wants to merge 2 commits into
python-injector:masterfrom
edsonsims:fix/noninjectable-type-hints
Open

edsonsims wants to merge 2 commits into
python-injector:masterfrom
edsonsims:fix/noninjectable-type-hints

Conversation

@edsonsims

Copy link
Copy Markdown

Fixes #258.

get_type_hints() currently tries to resolve annotations for parameters explicitly excluded with @noninjectable. An unresolved forward reference or a recursive alias from another module can therefore prevent a call even when the caller supplies that argument.

I filter those parameter names through the existing annotation proxy before type-hint evaluation, in both binding inference and initial Inject[...] discovery. Injected parameters still resolve normally and keep their existing errors. The regressions cover both decorator orders, constructors, stacked keyword-only exclusions, explicit discovery and missing required arguments.

Validation:

  • The original two-module example reproduces the error and succeeds with the change.
  • Nine focused cases: eight fail on the original source and one error-preservation control passes; all nine pass with the fix.
  • Full pytest/doctest suite: 154 passed on Python 3.13.1, with 97.11% coverage. The unchanged source passes its original 145 cases.
  • Mypy, Black, check-manifest, dependency consistency and git diff --check passed.
  • Fifteen independent behavioral checks passed on Python 3.10.16 and 3.13.1; these overlap the suite and are not added to its case count.

The change is limited to names declared with @noninjectable; general recursive-alias resolution and NoInject annotations retain their current behavior. Python 3.14 and PyPy were not run locally.

@codecov

codecov Bot commented Nov 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.51%. Comparing base (3177d40) to head (361f7bc).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #330      +/-   ##
==========================================
- Coverage   96.83%   96.51%   -0.33%     
==========================================
  Files           1        1              
  Lines         601      602       +1     
  Branches      103       97       -6     
==========================================
- Hits          582      581       -1     
- Misses         13       14       +1     
- Partials        6        7       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Return an empty annotation mapping when a builtin has no __annotations__.
Python 3.14 annotationlib otherwise rejects the noncallable proxy during
initial binding discovery, breaking inherited built-in initializers.

Add five regression cases for built-in functions, bound methods, method
descriptors and initialization wrappers. All five fail before this repair
on local Python 3.14.7 and pass afterwards. The full suite passes 159 tests
on macOS Python 3.13.1 and 3.14.7 with the existing 90% coverage threshold.
Mypy, Black, check-manifest and pip check pass on both local runtimes.
The failing remote environment is Linux Python 3.14.10; remote recovery
requires its next CI execution.
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.

Nonresolvable Type Hint on Non-Injected Argument Causes Error

1 participant