Skip to content

DecimalField should accept ints #2831

@sk-

Description

@sk-

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

_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.3
  • django version: 5.2.6
  • mypy version: 1.17.1
  • django-stubs version: 5.2.2
  • django-stubs-ext version: 5.2.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions