Enhancement: consider adding mypy plugin for type checking data.create_instance(id=1, address__id=2)
#3814
Labels
DTOs
This is related to our DTO feature
Enhancement
This is a new feature or request
Typing
This relates to typing
Summary
Right now
create_instance
can take any**kwargs
.But, mypy has no way of actually checking that
id=1, address__id=2
are valid keywords for this call.It can be caught when executed, sure. But typechecking is much faster than writing code + writing tests + running them.
In Django we have a similar pattern of passing keywords like this to filters. Like:
User.objects.filter(id=1, settings__profile="public")
. For this we use a custom mypy plugin: https://github.com/typeddjango/django-stubs/blob/c9c729073417d0936cb944ab8585ad236ab30321/mypy_django_plugin/transformers/orm_lookups.py#L10What it does?
__
ones also exist on the nested model**custom_data
unpackingtype: ignore[custom-code]
custom-code
is disabled in mypy checksPlus, in the future more goodies can be added, included DI proper checking, URL params, etc.
It will require its own set of tests via
typing.assert_type
and maintaince time. Mypy sometimes break plugin-facing APIs.I can write this plugin if others are interested :)
Basic Example
No response
Drawbacks and Impact
No response
Unresolved questions
No response
Note
While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.
Check out all issues funded or available for funding on our Polar.sh dashboard
The text was updated successfully, but these errors were encountered: