Skip to content

Unbreak pre-commit mypy on utils.py (missing stubs + wrong annotation)#49

Merged
scottstanie merged 1 commit intoopera-adt:mainfrom
scottstanie:chore/fix-precommit-mypy
Apr 24, 2026
Merged

Unbreak pre-commit mypy on utils.py (missing stubs + wrong annotation)#49
scottstanie merged 1 commit intoopera-adt:mainfrom
scottstanie:chore/fix-precommit-mypy

Conversation

@scottstanie
Copy link
Copy Markdown
Collaborator

Summary

Every commit touching utils.py was failing the pre-commit mypy hook locally because of two pre-existing issues:

  1. .pre-commit-config.yaml declared types-setuptools, types-requests, pydantic>=2.4, types-simplejson in the mypy hook's additional_dependencies — but not types-python-dateutil. Mypy runs in its own isolated env, so missing that stub tripped Library stubs not installed for "dateutil" on every run.

  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 annotation to match reality.

Things left alone

  • DateOrDatetimeT stays in the module — still used by datetime_to_float.
  • The # type: ignore[arg-type] comments on calculate_trend callers in main.py stay; 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, so any PR editing this file previously had to fix it anyway.

Test plan

  • pre-commit run mypy --files src/bowser/utils.py passes
  • pre-commit run mypy --files src/bowser/main.py still passes (callers' # type: ignore comments correctly preserved)
  • ruff / ruff-format pass

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

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>
@scottstanie scottstanie merged commit 2b678a8 into opera-adt:main Apr 24, 2026
0 of 2 checks passed
@scottstanie scottstanie deleted the chore/fix-precommit-mypy branch April 24, 2026 19:28
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