auto-typing-final


Nameauto-typing-final JSON
Version 1.0.1 PyPI version JSON
download
home_pageNone
SummaryAutomagically set typing.Final inside your functions
upload_time2025-07-15 13:29:49
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT
keywords automation flake8 mypy typing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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 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](docs/global_vars_enabled.md)).
- Ignores class variables: it is common to use `typing.ClassVar` instead of `typing.Final`.

## How To Use

Having uv installed:

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

or:

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

### Options

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

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

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

```sh
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:

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

### Ignore comment

You can ignore variables by adding `# auto-typing-final: ignore` comment to the line ([docs](docs/ignore_comment.md)).

### VS Code Extension

<img width="768" alt="image" src="https://github.com/community-of-python/auto-typing-final/assets/75225148/f1541056-06f5-4caa-8c94-0a5eaf98ba15">

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:

```sh
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).

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "auto-typing-final",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "automation, flake8, mypy, typing",
    "author": null,
    "author_email": "Lev Vereshchagin <mail@vrslev.com>",
    "download_url": "https://files.pythonhosted.org/packages/78/01/c7cbd3cc29cbfa0b2fb28199b9daba4ea70247d3d401fee24c640e7c1a1d/auto_typing_final-1.0.1.tar.gz",
    "platform": null,
    "description": "# auto-typing-final\n\nAuto-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.\n\n```diff\n def foo() -> None:\n-    a = 2\n+    a: typing.Final = 2\n\n-    b: typing.Final = 2\n+    b = 2\n     b = 3\n```\n\nBasically, this, but handles different operations (like usage of `nonlocal`, augmented assignments: `+=`, etc) as well.\n\n- Keeps type checker happy.\n- Adds global import if it's not imported yet (`import typing`/`from typing import Final`).\n- Inspects one file at a time.\n- 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](docs/global_vars_enabled.md)).\n- Ignores class variables: it is common to use `typing.ClassVar` instead of `typing.Final`.\n\n## How To Use\n\nHaving uv installed:\n\n```sh\nuvx auto-typing-final .\n```\n\nor:\n\n```sh\npipx run auto-typing-final .\n```\n\n### Options\n\nYou can specify `--check` flag to check the files instead of actually fixing them:\n\n```sh\nauto-typing-final . --check\n```\n\nAlso, you can choose import style from two options: `typing-final` (default) and `final`:\n\n```sh\nauto-typing-final . --import-style typing-final\n```\n\n- `typing-final` enforces `import typing` and `typing.Final`,\n- `final` enforces `from typing import Final` and `Final`.\n\nAlso, you can set `--ignore-global-vars` flag to ignore global variables:\n\n```sh\nauto-typing-final . --ignore-global-vars\n```\n\n### Ignore comment\n\nYou can ignore variables by adding `# auto-typing-final: ignore` comment to the line ([docs](docs/ignore_comment.md)).\n\n### VS Code Extension\n\n<img width=\"768\" alt=\"image\" src=\"https://github.com/community-of-python/auto-typing-final/assets/75225148/f1541056-06f5-4caa-8c94-0a5eaf98ba15\">\n\nThe 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:\n\n```sh\nuv add auto-typing-final --dev\n```\n\nAfter 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.\n\n### Settings\n\n- Import style can be configured in settings: `\"auto-typing-final.import-style\": \"typing-final\"` or `\"auto-typing-final.import-style\": \"final\"`.\n- Ignore global variables can be configured in settings: `\"auto-typing-final.ignore-global-vars\": true`.\n\n### Notes\n\nLibrary code of currently activated environment will be ignored (for example, `.venv/bin/python` is active interpreter, all code inside `.venv` will be ignored).\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Automagically set typing.Final inside your functions",
    "version": "1.0.1",
    "project_urls": {
        "Repository": "https://github.com/community-of-python/auto-typing-final"
    },
    "split_keywords": [
        "automation",
        " flake8",
        " mypy",
        " typing"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "9949f3146244b9781902ebeb732640187a5d7778e3ad0eea06545e38974c1851",
                "md5": "86010b9feb5ef3957894a84829354ac5",
                "sha256": "60acff2ffbadfde964796a7ebbc90f6cc2de9925317035ec0dcbfeca9ad27804"
            },
            "downloads": -1,
            "filename": "auto_typing_final-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "86010b9feb5ef3957894a84829354ac5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 12712,
            "upload_time": "2025-07-15T13:29:45",
            "upload_time_iso_8601": "2025-07-15T13:29:45.774505Z",
            "url": "https://files.pythonhosted.org/packages/99/49/f3146244b9781902ebeb732640187a5d7778e3ad0eea06545e38974c1851/auto_typing_final-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "7801c7cbd3cc29cbfa0b2fb28199b9daba4ea70247d3d401fee24c640e7c1a1d",
                "md5": "c21c5143b5c05410883074b2f5185ef9",
                "sha256": "6522ffdb2f1090c88dec9531c6e344f29d8f42089e060dd14e1f67b09628ae45"
            },
            "downloads": -1,
            "filename": "auto_typing_final-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "c21c5143b5c05410883074b2f5185ef9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 37294,
            "upload_time": "2025-07-15T13:29:49",
            "upload_time_iso_8601": "2025-07-15T13:29:49.206931Z",
            "url": "https://files.pythonhosted.org/packages/78/01/c7cbd3cc29cbfa0b2fb28199b9daba4ea70247d3d401fee24c640e7c1a1d/auto_typing_final-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-15 13:29:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "community-of-python",
    "github_project": "auto-typing-final",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "auto-typing-final"
}
        
Elapsed time: 1.47458s