Skip to content

Add Python type annotations and type checking to template #120

@ktaletsk

Description

@ktaletsk

Description

Currently, the extension template includes comprehensive linting and type checking for JavaScript/TypeScript (ESLint, TypeScript compiler, Prettier, Stylelint), but the Python code lacks type annotations and type checking tooling.

Proposal

Phase 1: Add Type Annotations

Add type hints to all Python code in the template:

  • Function parameters and return types
  • Class attributes and methods
  • Use modern Python typing features (typing module, Optional, Union, etc.)

Phase 2: Add Type Checker

Once type annotations are in place, add a type checker to verify them. Options:

Option 1: mypy (Community)

  • Open-source type checker developed by the Python community
  • De facto standard Python type checker
  • Extensive configuration options
  • Good for projects with gradual typing adoption
  • Reference: https://github.com/python/mypy

Option 2: Ruff (Astral Software Inc.)

  • Fast Python linter and formatter written in Rust
  • Can replace multiple tools (flake8, black, isort, etc.)
  • Growing type checking capabilities
  • Single tool for multiple purposes
  • Reference: https://github.com/astral-sh/ruff

Option 3: Pyright (Microsoft)

  • Fast type checker from Microsoft
  • Excellent IDE integration (native support in VS Code)
  • Very fast and accurate
  • Well-established in the ecosystem
  • Reference: https://github.com/microsoft/pyright

Option 4: Pyrefly (Meta)

  • Fast type checker and language server from Meta
  • Ground-up rebuild (not based on Pyre)
  • Combines type checking with language server features (code navigation, completion, semantic highlighting)
  • Provides migration path from Pyright
  • Reference: https://github.com/facebook/pyrefly

Benefits

  • Type Safety: Catch type-related bugs before runtime
  • Better IDE Support: Enhanced autocomplete, refactoring, and navigation
  • Documentation: Types serve as inline documentation
  • Consistency: Align Python code quality with existing JavaScript/TypeScript standards
  • Modern Python: Follow current best practices (PEP 484+)

Implementation

  1. Add type annotations to all Python files in template
  2. Add tool dependencies to [project.optional-dependencies] in pyproject.toml.jinja
  3. Add tool configuration sections to pyproject.toml.jinja
  4. Update AGENTS.md with commands to run type checking
  5. Consider adding pre-commit hooks or GitHub Actions for CI

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions