Metadata-Version: 2.3
Name: auto-typing-final
Version: 0.4.1
Project-URL: repository, https://github.com/vrslev/auto-typing-final
Author-email: Lev Vereshchagin <mail@vrslev.com>
License: MIT
License-File: LICENSE
Keywords: automation,flake8,mypy,typing
Classifier: Development Status :: 4 - Beta
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: ast-grep-py==0.24.1
Requires-Dist: pygls==1.3.1
Description-Content-Type: text/markdown

# auto-typing-final

Auto-fixer for Python code that adds `typing.Final` annotation to variable assignments inside functions that are not reassigned, and removes the annotation from variables that _are_ mutated.

```diff
 def foo() -> None:
-    a = 2
+    a: typing.Final = 2

-    b: typing.Final = 2
+    b = 2
     b = 3
```

Basically, this, but handles different operations (like usage of `nonlocal`, augmented assignments: `+=`, etc) as well.

- Keeps mypy happy.
- Ignores global variables to avoid confusion with the type aliases like `Fruit = Apple | Banana`.
- Ignores class variables: it is common to use `typing.ClassVar` instead of `typing.Final`.
- Adds global `typing` import if it's not imported yet.
- Inspects one file at a time.

## How To Use

Having uv installed:

```sh
uvx auto-typing-final .
```

or:

```sh
pipx run auto-typing-final .
```

You can specify `--check` flag to check the files instead of actually fixing them:

```sh
auto-typing-final . --check
```

You also can install VS Code extension. It uses installation of `auto-typing-final` from the current Python environment and shows diagnostics and quick fixes.

To get started, add `auto-typing-final` to your project:

```sh
uv add auto-typing-final --dev
```

or:

```sh
poetry add auto-typing-final --group=dev
```

And install the extension: https://marketplace.visualstudio.com/items?itemName=vrslev.auto-typing-final.
