Skip to content

Modernize type annotations to Python 3.9+ style #129

@jssmith

Description

@jssmith

Summary

Update type annotations throughout the codebase to use Python 3.9+ built-in generics instead of typing module equivalents.

Changes needed

Replace deprecated typing imports with built-in types:

  • List[X]list[X]
  • Dict[K, V]dict[K, V]
  • Set[X]set[X]
  • Tuple[X, Y]tuple[X, Y]
  • Optional[X]X | None
  • Union[X, Y]X | Y
  • Iterable, Generator → import from collections.abc

Files affected

  • src/postgres_mcp/database_health/database_health.py
  • src/postgres_mcp/index/index_opt_base.py
  • src/postgres_mcp/index/presentation.py
  • src/postgres_mcp/server.py
  • src/postgres_mcp/sql/safe_sql.py
  • tests/unit/index/test_dta_calc.py
  • tests/unit/sql/test_sql_driver.py
  • tests/utils.py

How to apply

Run:

uv run ruff check . --fix --unsafe-fixes
uv run ruff format .

Cleanup required

After applying fixes, remove the following lint.ignore rules from pyproject.toml:

# TODO: Remove these ignores when fixing #129 (code modernization)
lint.ignore = [
    "UP006",  # Use `list` instead of `List` for type annotations
    "UP035",  # Import from `collections.abc` instead of `typing`
    "UP045",  # Use `X | None` instead of `Optional[X]`
    "RUF059", # Unused unpacked variable
    "RUF100", # Unused noqa directive
]

Context

This was deferred during the dependency version bump (#130) to avoid breaking existing PRs with merge conflicts.

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