Skip to main content

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 type checker happy.
  • Adds global import if it's not imported yet (import typing/from typing import Final).
  • Inspects one file at a time.
  • Is careful with global variables: adds Final only for uppercase variables, ignores variable that are referenced in global statement inside functions in current file, and avoids removing Final when it already was set (docs).
  • Ignores class variables: it is common to use typing.ClassVar instead of typing.Final.

How To Use

Having uv installed:

uvx auto-typing-final .

or:

pipx run auto-typing-final .

Options

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

auto-typing-final . --check

Also, you can choose import style from two options: typing-final (default) and final:

auto-typing-final . --import-style typing-final
  • typing-final enforces import typing and typing.Final,
  • final enforces from typing import Final and Final.

Also, you can set --ignore-global-vars flag to ignore global variables:

auto-typing-final . --ignore-global-vars

Ignore comment

You can ignore variables by adding # auto-typing-final: ignore comment to the line (docs).

VS Code Extension

image

The extension uses LSP server bundled with the CLI (executable name is auto-typing-final-lsp-server). To get started, add auto-typing-final to your project:

uv add auto-typing-final --dev

After that, install the extension: https://marketplace.visualstudio.com/items?itemName=vrslev.auto-typing-final. In Python environments that have auto-typing-final installed, extension will be activated automatically.

Settings

  • Import style can be configured in settings: "auto-typing-final.import-style": "typing-final" or "auto-typing-final.import-style": "final".
  • Ignore global variables can be configured in settings: "auto-typing-final.ignore-global-vars": true.

Notes

Library code of currently activated environment will be ignored (for example, .venv/bin/python is active interpreter, all code inside .venv will be ignored).

Metadata

Release files for auto-typing-final 1.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for auto-typing-final 1.0.5
File Size Uploaded Provenance Actions
auto_typing_final-1.0.5.tar.gz 33.2 kB Without provenance Details for auto_typing_final-1.0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for auto-typing-final 1.0.5
File Interpreter ABI Platform Actions
auto_typing_final-1.0.5-py3-none-any.whl Python 3 none any Details for auto_typing_final-1.0.5-py3-none-any.whl

Total release size: 46.1 kB

Release files / auto_typing_final-1.0.5.tar.gz

Download URL auto_typing_final-1.0.5.tar.gz
Size 33.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4fb73e13e7ab6affc73d32846be86f19df547968a9106a74a1d42703ab52110c
BLAKE2b-256 checksum
How to use checksums
1f9e77b8af97cdfd4dfcf0cc95a7b51651c2204b33d957aee672c1b8d164e97f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / auto_typing_final-1.0.5-py3-none-any.whl

Download URL auto_typing_final-1.0.5-py3-none-any.whl
Size 12.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
590a3fe5697a5dde30057e4af48ca259fe9b0dcb14fe8864b08fe329cbca0dee
BLAKE2b-256 checksum
How to use checksums
3d93b4b9cb746ee3c924f300bc4b4904abc85430d150be1ecd39b353df2307c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for auto-typing-final 1.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page