Metadata-Version: 2.1
Name: django-autotyping
Version: 0.2.0
Summary: Automatically add type hints for Django powered applications.
Author-email: Viicos <65306057+Viicos@users.noreply.github.com>
License: MIT License
        
        Copyright (c) 2023 Viicos
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/Viicos/django-autotyping
Project-URL: Source, https://github.com/Viicos/django-autotyping
Project-URL: Changelog, https://github.com/Viicos/django-autotyping/blob/main/CHANGELOG.md
Project-URL: Documentation, https://viicos.github.io/django-autotyping/
Classifier: Development Status :: 4 - Beta
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Framework :: Django
Classifier: Typing :: Typed
Classifier: License :: OSI Approved :: MIT License
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Quality Assurance
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: django
Requires-Dist: libcst>=0.4.10
Requires-Dist: typing-extensions>=4.2.0; python_version < "3.11"

# Django Autotyping

[![Python versions](https://img.shields.io/pypi/pyversions/django-autotyping.svg)](https://www.python.org/downloads/)
[![PyPI version](https://img.shields.io/pypi/v/django-autotyping.svg)](https://pypi.org/project/django-autotyping/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

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

- generates custom [type stubs](https://typing.readthedocs.io/en/latest/source/stubs.html#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](https://viicos.github.io/django-autotyping/context/).

`django-autotyping` is built with [LibCST](https://github.com/Instagram/LibCST/).


> [!WARNING]\
> This project is still work in progress. It is meant to work with [`django-stubs`](https://github.com/typeddjango/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`:

```sh
pip install django-autotyping
```

To make use of the dynamic stubs feature, you will also need to install [`django-stubs`](https://github.com/typeddjango/django-stubs):

```sh
pip install django-stubs
```

## Configuration

As any Django application, you will need to add `django_autotyping` to your [`INSTALLED_APPS`](https://docs.djangoproject.com/en/dev/ref/settings/#std-setting-INSTALLED_APPS)
(preferably in your development or local settings, if you already have them separated).

The application is configurable through the `AUTOTYPING` dict:

```python
AUTOTYPING = {
    "STUBS_GENERATION": {
        "STUBS_DIR": Path(BASE_DIR, "typings"),
    }
}
```

> [!TIP]
> To get typing and auto-completion support, you can make use of the `AutotypingSettingsDict` helper:
>
>   ```python
>   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](https://viicos.github.io/django-autotyping/usage/dynamic_stubs/)
and [explicit type hints](https://viicos.github.io/django-autotyping/usage/explicit_type_hints/).
