Skip to content

fix(typing): widen Container.bind name param to str | type - #198

Merged
tmgbedu merged 1 commit into
mainfrom
task/bind-key-type-1249
Jul 25, 2026
Merged

fix(typing): widen Container.bind name param to str | type#198
tmgbedu merged 1 commit into
mainfrom
task/bind-key-type-1249

Conversation

@tmgbedu

@tmgbedu tmgbedu commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

What

Follow-up to #197 (merged as 7767a5cb). Post-merge review found one genuine new pyright error the bind() narrowing introduced.

Root cause

Container.simple() binds a class object as the container key:

self.bind(obj if inspect.isclass(obj) else obj.__class__, obj)

This mirrors make()'s class-key support (elif inspect.isclass(name):). The str-only bind(name: str, ...) signature from #197 was too narrow, so pyright errored at container/container.py:92:

Argument of type type[object] | Unknown cannot be assigned to parameter name of type str in function bind

Change

One-line signature widening — name: strname: str | type, matching the key types make() accepts. No runtime change; bind still returns None.

Verification

  • uv run pyright src/.../container.py: 0 errors (was 1 at :92). Before/after confirmed by temporarily reverting.
  • uv run pyright (full project): 0 container.py diagnostics; total 656 errors — no new errors introduced.
  • uv run pytest --ignore=tests/masoniteorm/postgres: 1981 passed, 7 skipped (incl. tests/core/test_container.py: 52 passed).
  • ruff check + ruff format --check: clean.

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.
@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@tmgbedu
tmgbedu merged commit 619dd49 into main Jul 25, 2026
6 checks passed
@tmgbedu
tmgbedu deleted the task/bind-key-type-1249 branch July 25, 2026 05:24
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