Opened 6 years ago

Last modified 2 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 Changed 6 years ago by Andreas Galazis

Description: modified (diff)

comment:2 Changed 6 years ago by Tim Graham

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 Changed 6 years ago by Adam Johnson

Cc: Adam Johnson added

comment:4 Changed 6 years ago by Zach Borboa

Cc: Zach Borboa added

comment:5 Changed 6 years ago by Andreas Galazis

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

comment:6 Changed 6 years ago by Vlastimil Zíma

Cc: Vlastimil Zíma added

comment:7 Changed 6 years ago by Brylie Christopher Oxley

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 Changed 6 years ago by Tim Graham

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

comment:9 Changed 5 years ago by Sergey Kolomenkin

Are there any updates on this ticket?

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

comment:10 Changed 5 years ago by Tim Graham

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

comment:11 Changed 4 years ago by Yngve Høiseth

Note the existence of django-stubs.

comment:12 Changed 2 years ago by Andreas Galazis

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 2 years ago by Andreas Galazis (previous) (diff)

comment:13 Changed 2 years ago by Thiago Bellini Ribeiro

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.

Version 0, edited 2 years ago by Thiago Bellini Ribeiro (next)
Note: See TracTickets for help on using tickets.
Back to Top