fix(typing): make Provider.boot() pattern static-analysis clean - #197
Merged
Conversation
Type Provider.app as Application[AppConfig] instead of the bare, generic Application so basedpyright/pyright resolves self.app concretely instead of Application[Unknown]. This stops the Unknown type from cascading into every self.app.* access (fastapi, use_base_path, include_router) inside provider boot()/register() methods. Give Container.bind an explicit signature. It now returns None (it never needs to be chained), so callers no longer see a partially-unknown member and the example provider can call self.app.bind(...) directly without capturing an unused result. Update the container test to assert the new None contract.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
tmgbedu
added a commit
that referenced
this pull request
Jul 25, 2026
simple() binds a class object as the container key (mirroring make()'s class-key support at 'elif inspect.isclass(name)'). The str-only signature from #197 was too narrow, producing a pyright error at container.py:92: 'Argument of type type[object] | Unknown cannot be assigned to parameter name of type str'. Widen name to str | type to match the keys make() accepts. Typing-only change; bind still returns None.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Makes the standard provider
boot()pattern pass basedpyright/pyright with noreportUnknownMemberType/Application[Unknown]diagnostics. Target snippet:Root cause
ApplicationisGeneric[TConfig], but theProviderbase class annotated itsappattribute as the bare, unparameterizedApplication. Static analyzers resolved that toApplication[Unknown], and the Unknown cascaded into everyself.app.*access (.fastapi,.use_base_path,.include_router). Separately,Container.bindhad no signature, soself.app.bind(...)and its result were reported as partially unknown.Changes
Provider: typeapp(and the__init__param) asApplication[AppConfig]— the concrete base config bound toTConfig.self.appnow resolves toApplication[AppConfig], clearing the cascade. Import is underTYPE_CHECKINGonly, so no runtime/import-cost change.Container.bind: explicit signature(name: str, class_obj: Any) -> None. Per direction,bindno longer returnsself— nothing chained on it (verified across framework,application/template, andexample/), so callers can writeself.app.bind(...)directly with no unused-result to capture.Nonecontract.Verification
pyright --typeCheckingMode strict) on the target snippet: 0 errors, 0 warnings.reveal_type(self.app)→Application[AppConfig];self.app.bind(...)→None.pytest --ignore=tests/masoniteorm/postgres: 1981 passed, 7 skipped.ruff check+ruff format --check: clean.Coordination
Complements the related typing work rather than duplicating it:
self.app), that PR fixes the method's own kwargs. They compose.No runtime behavior change beyond
Container.bindno longer returningself(an intentional, requested API tweak).