Django typing helper
Project description
django-autotyping
Automatically add type hints for Django powered applications.
[!WARNING]
Still WIP
[!NOTE]
As of today, generated type hints will only play well withdjango-types.django-stubsrequires a type for both the__set__and__get__types.
Installation
Through pip:
pip install django-autotyping
Usage
django-autotyping can be used as a CLI program:
usage: Add type hints to your models for better auto-completion.
positional arguments:
path Path to the directory containing the Django application. This directory should contain your `manage.py` file.
options:
-h, --help show this help message and exit
--settings-module SETTINGS_MODULE
Value of the `DJANGO_SETTINGS_MODULE` environment variable (a dotted Python path).
--disable [{DJA001} ...]
Rules to be disabled.
--type-checking-block
Whether newly added imports should be in an `if TYPE_CHECKING` block (avoids circular imports).
Rules
Add type hints to forward relations (DJA001)
All subclasses of RelatedField will be taken into account.
from typing import TYPE_CHECKING
from django.db import models
# Model is imported in an `if TYPE_CHECKING` block if `--type-checking-block` is used.
if TYPE_CHECKING:
# Related model is imported from the corresponding apps models module:
from myproject.reporters.models import Reporter
class Article(models.Model):
# If the field supports `__class_getitem__` at runtime, it is parametrized directly:
reporter = models.ForeignKey["Reporter"](
"reporters.Reporter",
on_delete=models.CASCADE,
)
# Otherwise, an explicit annotation is used. No unnecessary import if model is in the same file.
article_version: "models.OneToOneField[ArticleVersion]" = models.OneToOneField(
"ArticleVersion",
on_delete=models.CASCADE,
)
django-autotyping is built with LibCST.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django-autotyping-0.0.1.tar.gz.
File metadata
- Download URL: django-autotyping-0.0.1.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c41d1afc0b9ffd6b9d9013979ab1be97b6e501f371586af21541c7bf5ed9ec2
|
|
| MD5 |
b7356c9bacd2b028b35aa2b3a323a98b
|
|
| BLAKE2b-256 |
788bacd6d3a3fab2ddcf8d19cba1ee764cdc12eff4be542ef3c3cdbf43ed5a5a
|
File details
Details for the file django_autotyping-0.0.1-py3-none-any.whl.
File metadata
- Download URL: django_autotyping-0.0.1-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9625b11cb9664f1811ce502206e38d812e56d9f7153fe3fb4035fec934a00291
|
|
| MD5 |
75bca6b8eadb2332940b7e8db54c69b0
|
|
| BLAKE2b-256 |
9909fbc1674d38944e0b0725aafae89804435d993b5dd5f264bd6052989f63fc
|