Skip to content

Enforce strict mypy type checking and additional ruff rules#492

Open
FabianHofmann wants to merge 9 commits intomasterfrom
refac/type-annotation
Open

Enforce strict mypy type checking and additional ruff rules#492
FabianHofmann wants to merge 9 commits intomasterfrom
refac/type-annotation

Conversation

@FabianHofmann
Copy link
Contributor

@FabianHofmann FabianHofmann commented Mar 16, 2026

Changes proposed in this Pull Request

This PR enforces strict static type checking with mypy and enables additional ruff lint rules across the entire codebase (including test/ and doc/).

Docstrings

  • Add docstrings to all functions

Mypy

  • Configured strict mypy settings in pyproject.toml: disallow_incomplete_defs = true, check_untyped_defs = true
  • Removed all directory exclusions from mypy — it now checks atlite/, test/, and doc/
  • Updated .pre-commit-config.yaml to match
  • Leveraged existing atlite/_types.py type aliases and added TypeAlias annotations where needed (e.g. csp.py, utils.py)
  • Added missing type annotations to function signatures (e.g. conversion functions in convert.py)
  • Fixed __all__ in __init__.py to use strings instead of object references

Ruff

Enabled 9 new rule sets and fixed all violations (~260 fixes):

  • B (flake8-bugbear): Added from err/from None to re-raised exceptions, fixed mutable defaults
  • SIM (flake8-simplify): Collapsed nested if statements, simplified dict operations
  • RET (flake8-return): Removed superfluous else after return/raise
  • C4 (flake8-comprehensions): Simplified unnecessary dict()/list() constructors
  • TC (flake8-type-checking): Moved type-only imports into TYPE_CHECKING blocks
  • NPY (numpy): Replaced legacy np.random.seed/np.random.rand with np.random.default_rng
  • G (flake8-logging-format): Replaced f-strings in logging with lazy % formatting
  • PTH (flake8-use-pathlib): Replaced os.path.* and open() with pathlib equivalents
  • RUF100: Cleaned up unused # noqa comments

TODO

  • replace cast() where possible, need bump python version for mypy
  • add ruff check for docstring consistency

Checklist

  • Code changes are sufficiently documented; i.e. new functions contain docstrings and further explanations may be given in doc.
  • Unit tests for new features were added (if applicable).
  • Newly introduced dependencies are added to environment.yaml, environment_docs.yaml and setup.py (if applicable).
  • A note for the release notes doc/release_notes.rst of the upcoming release is included.
  • I consent to the release of this PR's code under the MIT license.

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