Skip to main content

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.

Keeps mypy happy.

  • Global import typing will be added if typing was not imported before.
  • Global variables are ignored to avoid confusion with the type aliases like Fruit = Apple | Banana.
  • Class variables are ignored since it is common to use typing.ClassVar instead of typing.Final.
  • One file at a time is inspected.

How To Use

uv tool run 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

VS Code key binding

Add to your keybindings.json:

{
  "key": "ctrl+shift+t",
  "when": "editorLangId == 'python'",
  "command": "runCommands",
  "args": {
    "commands": [
      "workbench.action.files.save",
      "workbench.action.terminal.newInActiveWorkspace",
      "workbench.action.terminal.toggleTerminal",
      {
        "command": "workbench.action.terminal.sendSequence",
        "args": {
          "text": "uv tool run auto-typing-final ${file}\u000Dexit\u000D"
        }
      }
    ]
  }
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

auto_typing_final-0.3.1.tar.gz (7.6 kB view hashes)

Uploaded Source

Built Distribution

auto_typing_final-0.3.1-py3-none-any.whl (6.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page