Skip to content

Latest commit

 

History

History
69 lines (50 loc) · 2.82 KB

README.md

File metadata and controls

69 lines (50 loc) · 2.82 KB

Django Autotyping

Python versions PyPI version Ruff

django-autotyping enhances your developing experience with Django by providing accurate type hints, without the need for a custom IDE or mypy plugin:

  • Generates custom type stubs based on the current state of your Django application, enhancing your development experience by providing auto-completions and accurate type checking.
  • Automatically add explicit type hints to your source code when type stubs are not enough.

To understand the why and how, you can refer to the context section.

django-autotyping is built with LibCST.

Warning

This project is still work in progress. It is meant to work with django-stubs, but some improvements and changes are probably going to be implemented in the stub definitions, and could potentially require some changes to the generated stubs.

Installation

Through pip:

pip install django-autotyping

To make use of the dynamic stubs feature, you will also need to install django-stubs:

pip install django-stubs

Configuration

As any Django application, you will need to add django_autotyping to your INSTALLED_APPS (preferably in your development or local settings, if you already have them separated).

The application is configurable through the AUTOTYPING dict:

AUTOTYPING = {
    "STUBS_GENERATION": {
        "LOCAL_STUBS_DIR": Path(BASE_DIR, "typings"),
    }
}

Tip

To get typing and auto-completion support, you can make use of the AutotypingSettingsDict helper:

from django_autotyping.typing import AutotypingSettingsDict

AUTOTYPING: AutotypingSettingsDict = {
    ...
}

django-autotyping provides several linting rules, identified with the pattern DJA00X or DJAS00X. Rules can be disabled using the IGNORE setting value.

For a complete list of available configuration values, refer to the usage section of dynamic stubs and explicit type hints.