Hi, I'm the original creator of https://github.com/typeddjango/django-stubs.
I guess it's my duty to start writing a DEP, so here is some preliminary
thoughts/questions to gather early feedback:
Main discussion points:
1. There's two ways to make Django compatible with type hinting and PEP484:
- Separate repo with `.pyi` files and mypy plugin (how it's done
currently with django-stubs).
Pros:
- no backwards-incompatible changes. Only required change from
Django is adding the `__class_getitem__` method to `QuerySet`
https://docs.python.org/3/reference/datamodel.html#object.__class_getitem__
to support generic parameters in 3.7+
- could be released separately
- no type hints code clutter
Cons:
- (as of now) there's no way to use type hints to typecheck Django
codebase itself. I think the official answer to that is to use retype tool
https://github.com/ambv/retype
(https://github.com/python/mypy/issues/5028#issuecomment-495942769), but so
far I didn't have any positive experience with that
- Inline type hints in the codebase.
Pros/Cons are exact reverse.
2. Whether to use Django own machinery to extract info for the
models/fields, or not.
Current implementation of django-stubs utilises `Apps` registry of Django
itself to extract some data for models/fields.
So, basically it executes codes first, then performs static analysis of
it.
Pros:
- lots of models/fields introspection could be extracted from the
`_meta` API => lower maintenance burden, more accurate types. In the
pre-1.0.0 versions of the django-stubs it was all done statically, and it
was very painful to implement.
Cons:
- mypy daemon mode (dmypy) is broken. It could be fixed, but it
requires some changes to mypy itself, and as `django.setup()` could not run
incrementally, it's not clear whether dmypy would provide any real benefits
over plain incremental mode.
- there could be some side effects in `django.setup()` invocation
- cannot typecheck invalid code
- slower to execute
Carlton, is it possible to move discussion to Github somehow?
On Wednesday, December 12, 2018 at 7:06:16 PM UTC+3, Carlton Gibson wrote:
>
> Hi all.
>
>
> Where are we with this Type Hinting work?
>
>
> I just closed https://code.djangoproject.com/ticket/30019 as needsinfo
> pointing back to this thread.
>
>
> As far as I can see:
>
> * There's keenness for this.
> * There's a number of people who are prepared to put in the effort.
> * But we just need a strategy.
>
> It looks then like a coordination problem. Do we just need to get said
> people in a (virtual) room...?
>
> Maybe one of you — anyone — opening a DEP to begin the conversation would
> be enough..
> (That's just an idea.)
>
> Looking here:
> https://github.com/django/deps/blob/master/final/0001-dep-process.rst#dep-submission-workflow
> I'd guess "Forming the Team" is relevant.
>
> Happy to help if I can.
> (I recall Frank mentioned it no too long ago...)
>
> Kind Regards,
>
> Carlton
>
>
--
You received this message because you are subscribed to the Google Groups
"Django developers (Contributions to Django itself)" 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-developers/c659f5aa-0ce5-4e65-a983-e98f3f6dfb3d%40googlegroups.com.