Skip to main content

Automatically add type hints for Django powered applications.

Project description

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.

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"),
    }
}

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.

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

django_autotyping-0.5.1.tar.gz (79.0 kB view hashes)

Uploaded Source

Built Distribution

django_autotyping-0.5.1-py3-none-any.whl (96.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page