ITADN

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

#3148Openahmedasar00 创建于 2026-03-02
A
ahmedasar00commented
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: ```Plaintext 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) `` 2. Missing members in django.utils.inspect The runtime has lock and safe_signature_from_callable which are completely missing from the stubs. Errors: ```Plaintext 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`?
0 条评论