No project description provided
Project description
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.
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 oftyping.Final
. - Adds global
typing
import if it's not imported yet. - Inspects one file at a time.
How To Use
Having uv installed:
uvx auto-typing-final .
or:
pipx run auto-typing-final .
You can specify --check
flag to check the files instead of actually fixing them:
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:
uv add auto-typing-final --dev
or:
poetry add auto-typing-final --group=dev
And install the extension: https://marketplace.visualstudio.com/items?itemName=vrslev.auto-typing-final.
Project details
Release history Release notifications | RSS feed
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
Hashes for auto_typing_final-0.5.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e75e9b4cc40522660d78eb321cfea19d2d675ab3aae4df70499a4fefb65a746f |
|
MD5 | 3ea433144690d0bffa7df4404e6f166b |
|
BLAKE2b-256 | ef032d213104ede8fd53bdf4082996b16b51424cd09c415b20c4b6611840e762 |