Add type hints propagation and mypy/radon to CI#71
Merged
Conversation
Propagate signature-level type annotations outward from the simulation.py / elements.py seed to the remaining six first-party modules (alphadeesp.py, graphsAndPaths.py, network.py, printer.py, Grid2opSimulation.py, PypownetSimulation.py). Type-annotated function count goes from 36 to ~220 return-type annotations. Wire mypy --ignore-missing-imports into CircleCI: strict mode for the seed (simulation.py, elements.py) gates the build, permissive mode for the rest of the tree is informational (guarded with `|| true`) until the local-variable annotations catch up. Config lives in a new [mypy] section of setup.cfg with per-module overrides for the seed. Add a dedicated "Code quality metrics" CI step that runs `radon cc/mi/ raw` on every build, making cyclomatic complexity, maintainability index, and raw SLOC metrics visible per build without a local radon install. All radon commands are informational-only. Also add base-class attribute annotations for Simulation.param_options and Simulation.debug so the strict-mode seed run keeps passing after the propagation lands. Docs: docs/code-quality-analysis.md updated with "Type hints propagation", "Mypy in CI", and "Code quality metrics in CI" sections; item 14 marked done with a follow-up note on the remaining ~51 permissive-mode mypy findings (needs-local-annotation on internal dicts/lists; int/float mismatches in AlphaDeesp hot loops).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR completes the type-hints rollout across the alphaDeesp codebase and integrates static type checking and code quality metrics into the CircleCI pipeline.
Key Changes
Type Hints Propagation
core/alphadeesp.py(~38 signatures)core/graphsAndPaths.py(~76 signatures)core/network.py(3 key signatures + attributes)core/printer.py(7 methods/functions)core/grid2op/Grid2opSimulation.py(~33 signatures)core/pypownet/PypownetSimulation.py(~27 signatures)Simulation(param_options,debug) to support strict-mode checking in seed modulesAnypragmatically for backend-specific objects (Grid2op observations, pypownet environments, rustworkx graphs) where precise types are unavailabledefsignatures andtypingimports were modifiedMypy Integration in CI
mypy --ignore-missing-importsto CircleCIbuild-and-testjobcore/simulation.py,core/elements.py) — failures block the build|| trueguard)setup.cfgwith per-module overridesCode Quality Metrics in CI
radonstep to CircleCI for automated code quality reporting:radoncommands guarded with|| true— purely informational, never fails the buildradoninvocations documented in the analysis guideDocumentation Updates
docs/code-quality-analysis.mdwith:Implementation Details
Anyover guessing for backend objects; usednetworkx.MultiDiGraph,pandas.DataFrame,Sequence[float]for clear contracts; propagated abstract-base-class return types to concrete backends for Liskov-style checksignore_missing_imports = Truesilences stubs from grid2op, lightsim2grid, networkx, rustworkx, pypowsyblfollow_imports = silentprevents permissive run from cascading into strict-scope errorshttps://claude.ai/code/session_0173Le82Tq8axHhYJWfEBCgD