#31223: Add __class_getitem__ to support runtime type parameters for some
classes
-------------------------------------+-------------------------------------
Reporter: Sobolev | Owner: nobody
Nikita |
Type: New | Status: new
feature |
Component: Utilities | Version: master
Severity: Normal | Keywords: types, mypy,
Triage Stage: | django-stubs
Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
We (in django-stubs) treat several types as Generics. We provide type
parameters to them like so: `QuerySet[MyModel]`
Currently it is impossible without a monkeypatch from our side, because
these classes do not have `__class_getitem__` method.
Suggested patch will address this problem for:
- cached_property
- Lookup
- Field
- QuerySet
- BaseManager
Implementation detail: `__class_getitem__` will be a no-op for django
runtime. Since types are only required during `mypy` check.
django-stubs: https://github.com/typeddjango/django-stubs
monkey-patching: https://github.com/typeddjango/django-
stubs/blob/5b3088a17a76a77cb56a9c2241c2ddc6ccc8153a/mypy_django_plugin/django/context.py#L60-L61
Related DEP: https://github.com/django/deps/pull/65
--
Ticket URL: <https://code.djangoproject.com/ticket/31223>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.db010a240bf2e168592ae35d9461ba3b%40djangoproject.com.