Skip to content

Add Python 3.11+ type hints to core modules#51

Merged
alingse merged 2 commits intomasterfrom
upgrade-python-311-type-hints
Feb 10, 2026
Merged

Add Python 3.11+ type hints to core modules#51
alingse merged 2 commits intomasterfrom
upgrade-python-311-type-hints

Conversation

@alingse
Copy link
Owner

@alingse alingse commented Feb 10, 2026

Summary

  • Add type annotations to dumptool.py, jsontool.py, main.py, and utils.py
  • Use modern Python 3.11+ syntax (e.g., set[str] instead of Set[str])
  • Add io and typing imports for proper type hints
  • Import JsonType from utils for consistent JSON type annotations
  • Add return type annotations to all functions

Changes

This PR enhances type safety by adding comprehensive type hints across the core modules using Python 3.11+ syntax.

Test plan

  • Existing tests pass
  • Type checker (e.g., mypy) validates the new type hints

- Add type annotations to dumptool.py, jsontool.py, main.py, and utils.py
- Use modern Python 3.11+ syntax (e.g., set[str] instead of Set[str])
- Add io and typing imports for proper type hints
- Import JsonType from utils for consistent JSON type annotations
- Add return type annotations to all functions
- CI workflow: Remove Python 3.8/3.9/3.10, keep 3.11/3.12/3.13/3.14
- pyproject.toml: Add Python 3.14 classifier, update ruff target-version to py311, mypy to 3.11
- Add pytest-cov to dependency-groups for test coverage
- Modernize all type hints to Python 3.11+ syntax:
  - Union[X, Y] → X | Y
  - Optional[X] → X | None
  - List[X] → list[X]
  - Dict[X, Y] → dict[X, Y]
  - Tuple[X, Y] → tuple[X, Y]
- Import from collections.abc instead of typing for Callable, Iterable, Iterator
- Add strict=True to zip() call
- Use ternary operator for fout assignment in main.py
@alingse alingse merged commit ddf7566 into master Feb 10, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant