Unbreak pre-commit mypy on utils.py (missing stubs + wrong annotation)#49
Merged
scottstanie merged 1 commit intoopera-adt:mainfrom Apr 24, 2026
Merged
Conversation
Two pre-existing issues that together broke the mypy hook: 1. `.pre-commit-config.yaml` didn't declare `types-python-dateutil` in mypy's `additional_dependencies`. mypy runs in its own isolated env, so missing that stub tripped `Library stubs not installed for "dateutil"` on every commit touching a file that imports dateutil. 2. `calculate_trend`'s signature advertised `list[str | int | DateOrDatetimeT]` but delegated to `_parse_x_values(list[str | int])`. The wider type was wishful — `_parse_x_values` ultimately calls `dateutil.parser.parse`, which only accepts strings; passing a `datetime` object would error at runtime. Narrowed the signature to match reality. `DateOrDatetimeT` stays in the module — it's still used by `datetime_to_float`. The `# type: ignore[arg-type]` comments on the `calculate_trend` callers in `main.py` are left alone; `list` is invariant, so `list[str]` still isn't assignable to `list[str | int]` without the suppression. Drive-by: fixed one unrelated pre-existing E501 in a docstring — ruff only flags it on full-file recheck. CI already runs green (CI only runs pytest, not pre-commit); this just unbreaks the local commit loop. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Every commit touching
utils.pywas failing the pre-commitmypyhook locally because of two pre-existing issues:.pre-commit-config.yamldeclaredtypes-setuptools,types-requests,pydantic>=2.4,types-simplejsonin the mypy hook'sadditional_dependencies— but nottypes-python-dateutil. Mypy runs in its own isolated env, so missing that stub tripped Library stubs not installed for "dateutil" on every run.calculate_trend's signature advertisedlist[str | int | DateOrDatetimeT]but delegated to_parse_x_values(list[str | int]). The wider type was wishful —_parse_x_valuesultimately callsdateutil.parser.parse, which only accepts strings; passing adatetimeobject would error at runtime. Narrowed the annotation to match reality.Things left alone
DateOrDatetimeTstays in the module — still used bydatetime_to_float.# type: ignore[arg-type]comments oncalculate_trendcallers inmain.pystay;listis invariant, solist[str]still isn't assignable tolist[str | int]without the suppression.Drive-by
Fixed one unrelated pre-existing
E501in a docstring — ruff only flags it on full-file recheck, so any PR editing this file previously had to fix it anyway.Test plan
pre-commit run mypy --files src/bowser/utils.pypassespre-commit run mypy --files src/bowser/main.pystill passes (callers'# type: ignorecomments correctly preserved)CI only runs pytest, not pre-commit, so none of this shows in the CI check — but every local commit loop was broken on this file.
🤖 Generated with Claude Code