#31223: Add __class_getitem__ to support runtime type parameters for some
classes
-------------------------------------+-------------------------------------
Reporter: Sobolev Nikita | Owner: nobody
Type: New feature | Status: new
Component: Utilities | Version: master
Severity: Normal | Resolution:
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
-------------------------------------+-------------------------------------
Comment (by Ran Benita):
Instead of adding a custom dummy `__class_getitem__()` implementation,
another approach is to actually inherit from `typing.Generic`. As long as
Django doesn't publish its types with a `py.typed` file, it should not
have an effect on type-checking, but it will add the necessary
`__class_getitem__` at runtime:
https://github.com/python/cpython/blob/78c7183f470b60a39ac2dd0ad1a94d49d1e0b062/Lib/typing.py#L876
The reason to do this is that presumably the `__class_getitem__` runtime
implementation in `typing` is more correct (certainly seems to do a lot)
and more forward compatible than a custom implementation in Django would
be.
There might be repercussions I am not considering though, like
performance, or side effects of importing `typing`.
--
Ticket URL: <https://code.djangoproject.com/ticket/31223#comment:1>
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/066.f20fb4db2a048559fe98f958eb03e1e1%40djangoproject.com.