Skip to content

Validate Factory kwargs against creator signature and use is-check against UNSET#194

Merged
lesnik512 merged 1 commit into
mainfrom
factory-py-nice-to-have-fixes
Jun 5, 2026
Merged

Validate Factory kwargs against creator signature and use is-check against UNSET#194
lesnik512 merged 1 commit into
mainfrom
factory-py-nice-to-have-fixes

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Summary

Two `Factory` fixes from the 2026-06-05 bug-hunt audit (nice-to-have items #4 and #13).

  • `Factory` now validates static `kwargs` against the creator's signature at construction time. A typo like `{'connetion_string': ...}` previously surfaced only at instantiation as a raw `TypeError` from Python with no provider identity. The new `UnknownFactoryKwargError(RegistrationError)` raises at `Factory.init` naming the offending keys and using `difflib.get_close_matches` to suggest the closest valid name. Validation is automatically skipped when the creator accepts `**kwargs` (`VAR_KEYWORD`) or when its signature is uninspectable.
  • `_compile_kwargs` now uses `is` against `UNSET` instead of `==`. A parameter with `default=unittest.mock.ANY` (whose `eq` returns `True` for any comparand) used to spuriously match `v.default == UNSET`, raising `ArgumentResolutionError` instead of using the default. One-character fix; matches the `UnsetType.doc` guidance in `modern_di/types.py`.

Five new regression tests cover: unknown-kwarg raise, did-you-mean suggestion, `**kwargs` bypass, uninspectable-signature bypass, and `mock.ANY`-style default with custom `eq`.

Test plan

  • 5 new tests pass; full suite green (144 passed).
  • 100% coverage maintained.
  • `just lint-ci` green.

🤖 Generated with Claude Code

@lesnik512
lesnik512 force-pushed the factory-py-nice-to-have-fixes branch from 4cda9f9 to b6b0184 Compare June 5, 2026 19:39
@lesnik512 lesnik512 self-assigned this Jun 5, 2026
@lesnik512
lesnik512 merged commit 0951fc1 into main Jun 5, 2026
7 checks passed
@lesnik512
lesnik512 deleted the factory-py-nice-to-have-fixes branch June 5, 2026 19:40
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