Repository navigation
Enhancement | Type check leverage/ with mypy (gradual) in CI - #355
Conversation
- Runner.run: overloads, int when interactive, (code, stdout, stderr) when not - leverage.py: import each command from its module (leverage.modules.aws and the like are also submodules, so mypy saw modules instead of commands) - get_option_value in _utils: a ConfigUpdater option value is Optional; a missing value now raises NoOptionError instead of AttributeError on None. Used by auth.py and aws.py - Optional for arguments defaulting to None, renamed variables reused with another type, Group assert in _handle_subcommand - Two commented ignores: TFRunner.run is always interactive, and the type of the `run` command can't be inferred through the leverage/__init__ import cycle No behavior change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
mypy 1.19.1 (the last release that runs on and checks for Python 3.9) and types-python-dateutil as dev dependencies, a gradual [tool.mypy] config (annotated code only, no stubs for boto3/botocore/simple_term_menu) and a step in the required unit_tests job, on 3.13 only. Coverage skips @overload stubs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
No actionable comments were generated in the recent review. WalkthroughThe pull request adds mypy to the development dependencies and unit-test workflow. It adds a configuration option helper, uses it in authentication and AWS code, and updates runner return types and other annotations. Changesmypy Adoption
Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Other Suggested reviewers: Merge Risk:
|
Coverage Report for CI Build 43650528200Coverage increased (+0.2%) to 77.28%Details
Uncovered ChangesNo uncovered changes found. Coverage Regressions41 previously-covered lines in 7 files lost coverage.
Coverage Stats
💛 - Coveralls |
|
@coderabbitai review |
Action performed
|
What?
mypynow type checksleverage/in the requiredunit_testsjob. It starts with the 52 errors it found fixed.mypy1.19.1, the last release that runs on and checks for Python 3.9 (1.20 dropped it), plustypes-python-dateutil.[tool.mypy]: it checks annotated code only, so unannotated functions can be added module by module later (e.g.check_untyped_defs).boto3,botocoreandsimple_term_menupublish no types and are ignored.unit_tests, on 3.13 only: it checks for 3.9 whatever the runtime. It is not a pre-commit hook, because it needs all the dependencies installed.The errors
8 came from libraries without types. The other 44 were fixed in the code, without changing behavior:
Runner.runintwhen interactive,(code, stdout, stderr)when not._handle_subcommandwas handing the union toclick.Exitleverage.pyleverage.modules.awsand the like are also submodules, so mypy saw modules instead of commandsget_option_valuehelper in_utils.py(with tests), used inauth.pyandaws.py. A missing MFArole_arnnow raisesNoOptionErrornaming the option, notAttributeErroronNonepath.py,kubectl.py,auth.py,credentials.py,modules/utils.pyOptionalforNonedefaults, renamed variables reused with another type, aGroupassertTwo commented
# type: ignores:TFRunner.runis always interactive, on purpose:exec()captures the output.runcommand through theleverage/__init__↔leverage.leverageimport cycle.The account lookup in
aws configure ssois typed asAny: it walks the HCL data by catchingAttributeError. Rewriting it is out of scope here.Results
mypy: no issues in 22 files.@overloadstubs.Relates to #346
🤖 Generated with Claude Code
Summary by CodeRabbit