Skip to content

stubtest: Inconsistencies in TextChoices, IntegerChoices and missing members in django.utils.inspect #3148

Description

@ahmedasar00

Description:

Running ./scripts/stubtest.sh on the current version of django-stubs reveals several inconsistencies between the stubs and the runtime environment.

  1. Choices Classes Inconsistency (__init__ vs __new__)

Multiple errors indicate that IntegerChoices and TextChoices define __init__ with parameters in the stubs, but at runtime, these parameters do not exist in __init__. The error message suggests moving the logic to __new__.

Affected modules:

  • django.db.models.enums

  • django.contrib.gis.db.models

  • django.tasks.base

Example Error:

error: django.db.models.enums.IntegerChoices.__init__ is inconsistent, runtime does not have parameter "x". 
You may need to write stubs for __new__ instead of __init__.
Stub: Overload(def (self: ..., x: ...), def (self: ..., x: ..., label: ...))
Runtime: def (self)
  1. Missing members in django.utils.inspect

The runtime has lock and safe_signature_from_callable which are completely missing from the stubs.

Errors:

error: django.utils.inspect.lock is not present in stub
error: django.utils.inspect.safe_signature_from_callable is not present in stub

Environment:

Django version: [Write your Django version here, e.g., 5.0]

Python version: [Write your Python version here, e.g., 3.12]

Command run: `./scripts/stubtest.sh`

Question:

Is this expected behavior for the current state of the stubs, or should these be addressed by moving the signatures to __new__ and adding the missing members to django.utils.inspect?

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions