#32156: Add __class_getitem__ to support runtime type parameters for more 
classes
-------------------------------------+-------------------------------------
     Reporter:  Brady Kieffer        |                    Owner:  Brady
                                     |  Kieffer
         Type:  New feature          |                   Status:  assigned
    Component:  Utilities            |                  Version:  2.2
     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:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Brady Kieffer):

 Hi Carlton,

 Thanks for the speedy response. I guess I just want to preface everything
 here by saying I pretty squarely fall into the bucket of being a user of
 both `Django` + `django-stubs`. I definitely agree that the code is a bit
 boilerplate-y. I don't actually think this is a mypy issue, it's more
 about how we choose to reconcile the true implementation of Django with
 third party libraries attempting to type it in a simple manner. So, when
 it comes to:

 {{{
 @classmethod
 def __class_getitem__(cls, *args, **kwargs):
     return cls
 }}}

 I tend to agree that it's pretty annoying that we have to modify Django to
 make it usable with `django-stubs`. In defense of `mypy` and typing in
 general, there's a more idiomatic approach to this problem by defining a
 class as a `Generic` ([https://mypy.readthedocs.io/en/stable/generics.html
 #defining-generic-classes docs for Generics here]). I _believe_ the reason
 that adding `Generic` as a base for `QuerySet` + `Manager` was avoided
 because it could have an impact downstream but, I don't really know why
 this was decided. So, `mypy` would recommend we use `Generic`, which we
 likely will not, and it sort of leaves open the question of what should we
 reasonably expect to do with Django **if** we want to support third party
 typing libraries. I'm not super opinionated, but I would definitely rather
 not have to monkeypatch every codebase that uses django-stubs if it can be
 avoided. If we do go down this path though, I would agree that your second
 point will likely never be satisfied.

 Type checking is really cool, and it's saved us from some very weird bugs.
 But, it definitely feels like we're in a weird middle ground where there
 isn't "the one perfect way" of doing it.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32156#comment:3>
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/070.0f998f1526d996f1ed87da93b2f3d0c1%40djangoproject.com.

Reply via email to