-
-
Notifications
You must be signed in to change notification settings - Fork 506
Description
Bug report
The type definitions for DecimalField
are too strict and do not allow to query them with ints.
What's wrong
We are enabling the plugin in one of our codebases and we are getting a bunch of errors of the form
error: Incompatible type for lookup 'total_amount': (got "int", expected "str | Decimal") [misc]
This happens, because the type definition for DecimalField. _pyi_lookup_exact_type
is too strict and does not include "float" like _pyi_private_set_type
django-stubs/django-stubs/db/models/fields/__init__.pyi
Lines 264 to 266 in ed5046e
_pyi_private_set_type: str | float | decimal.Decimal | Combinable | |
_pyi_private_get_type: decimal.Decimal | |
_pyi_lookup_exact_type: str | decimal.Decimal |
How is that should be
Code that works without typing should rarely be changed in order to accommodate types, unless of course there is an underlying typing issue. In this case I think no error should be raised as the conversion is safe, and at the very least we should add int
to DecimalField. _pyi_lookup_exact_type
.
System information
- OS: macOS Sequoio 15.6.1
python
version: 3.13.3django
version: 5.2.6mypy
version: 1.17.1django-stubs
version: 5.2.2django-stubs-ext
version: 5.2.2