Opened 7 years ago

Last modified 3 years ago

#29299 new Cleanup/optimization

Add type hints (PEP 484) and variable annotations (PEP 526)

Reported by: Andreas Galazis Owned by: nobody
Component: Core (Other) Version: 2.0
Severity: Normal Keywords:
Cc: Adam Johnson, Zach Borboa, Vlastimil Zíma Triage Stage: Someday/Maybe
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Andreas Galazis)

Adhering to Type hints(PEP 484) / type annotations could contribute to being more explicit / performing code analysis and checks on Django projects. Intellisense based on type annotations can also contribute to faster and less error-prone coding experience.

Typesheds will be a pain to maintain across versions. Based on my experience with typescript typings, the most immaculate situation is shipping typings within the project, even though shipping external typings is mature in that case. Nevertheless, inline typings can help Django project development as well.

Adding to the docs any future plans regarding this would be helpful to prospective developers.

Change History (13)

comment:1 by Andreas Galazis, 7 years ago

Description: modified (diff)

comment:2 by Tim Graham, 7 years ago

Component: UncategorizedCore (Other)
Summary: Inline/Out of the box Type hints(PEP 484) and Variable annotations(PEP 526)Add typing hinting (PEP 484) and variable annotations (PEP 526)
Triage Stage: UnreviewedSomeday/Maybe

This is discussed on django-developers but a consensus on how to proceed hasn't emerged.

comment:3 by Adam Johnson, 7 years ago

Cc: Adam Johnson added

comment:4 by Zach Borboa, 7 years ago

Cc: Zach Borboa added

comment:5 by Andreas Galazis, 7 years ago

Summary: Add typing hinting (PEP 484) and variable annotations (PEP 526)Add type hints (PEP 484) and variable annotations (PEP 526)

comment:6 by Vlastimil Zíma, 7 years ago

Cc: Vlastimil Zíma added

comment:7 by Brylie Christopher Oxley, 6 years ago

I am available to help with this issue. Is there a checklist of files or areas, so that I can take a few to start?

comment:8 by Tim Graham, 6 years ago

See comment 2 and post on the mailing list if you want to try to get a consensus on a way forward.

comment:9 by Sergey Kolomenkin, 6 years ago

Are there any updates on this ticket?

Does Django has some roadmap for adding type hints support to Django?

comment:10 by Tim Graham, 6 years ago

No updates. The discussion is on the mailing list linked in comment 2.

comment:11 by Yngve Høiseth, 5 years ago

Note the existence of django-stubs.

comment:12 by Andreas Galazis, 3 years ago

Adding them in the framework would make changes to the framework more smooth since typings would be updated within the codebase and there will be no need for a new stub release (or waiting for the stub release).
I understand that it might involve a bit of donkey work to merge the stubs in the framework.
If we find a tool to merge it automatically, would it be acceptable?
As a sidenote, I stumbled on this:
https://pypi.org/project/retype/

Last edited 3 years ago by Andreas Galazis (previous) (diff)

comment:13 by Thiago Bellini Ribeiro, 3 years ago

Just to add here too, this project here is a fork of the original django-stubs but without the mypy dependency and that works fine with pyright.
It has some interesting stuff in it, like defined a field with null=True/null=False automatically types it as being able to get/set None together with the field's primary type.

edit: Forgot to add the link to the repository itself: https://github.com/sbdchd/django-types

Last edited 3 years ago by Thiago Bellini Ribeiro (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top