Skip to content

Skip type-hint resolution for noninjectable parameters - #330

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

edsonsims wants to merge 1 commit 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.

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