Skip to content

chore: fix pre-commit.ci on Python 3.14; pass ruff 0.17 and mypy 2.x - #153

Draft
bluetoothbot wants to merge 3 commits into
Bluetooth-Devices:mainfrom
bluetoothbot:koan/ruff-mypy-forward-compat
Draft

bluetoothbot wants to merge 3 commits into
Bluetooth-Devices:mainfrom
bluetoothbot:koan/ruff-mypy-forward-compat

Conversation

@bluetoothbot

@bluetoothbot bluetoothbot commented Oct 25, 2026 •

Copy link
Copy Markdown

What: Make the code pass the hook versions in the pre-commit autoupdate PR #131 (ruff 0.17, mypy 2.4). The currently pinned versions still pass.

Why — pre-commit.ci is red on every open PR, and on main if it re-ran. pre-commit.ci now uses Python 3.14 by default. On 3.14, pyupgrade v3.21.0 raises TypeError: cannot use a bytes pattern on a string-like object because tokenize.cookie_re became a bytes pattern. The GitHub Actions lint job runs on 3.11, so it stays green. That explains why every PR since early 2026 is red on pre-commit.ci only, while #132–#135 (Dec 2025/Jan 2026) were green. I reproduced it on main with Python 3.14.2 and 3.14.5. pyupgrade 3.21.2 and 3.22.0 fix it, so this PR bumps the rev to v3.22.0, the same line as #131.

Also: #131 fails pre-commit.ci. Newer ruff enables more rules by default, and the repo has no ruff config. pre-commit.ci's autofix commit fixes some of them but leaves:

  • 3 ruff errors: EXE001 on setup.py, RUF015 on data.py:99, and PYI018 (the TypeVar left unused by its own fix)
  • 2 mypy unused-ignore errors in tests/test_init.py

That autofix also adds a runtime from typing import Self to enum.py. That import raises ImportError on Python 3.9 and 3.10, which pyproject.toml still declares as supported (^3.9). CI only tests 3.11+, so CI wouldn't catch it.

How:

  • .pre-commit-config.yaml: pyupgrade v3.21.0 → v3.22.0. chore(pre-commit.ci): pre-commit autoupdate #131 makes the same change, so the two don't conflict.
  • enum.py: use Self instead of the custom TypeVar, imported only under TYPE_CHECKING. The module already has from __future__ import annotations, so Self is never evaluated at runtime. This works with or without feat: require Python 3.11 or later #152.
  • setup.py: removed the shebang. The file isn't executable in git, and python setup.py still works.
  • data.py: next(iter(...)) in primary_device_id. int | float becomes float in the two native_value annotations. The type is unchanged, because type checkers already accept int where float is expected.
  • __init__.py: sorted __all__. docs/source/conf.py: List becomes list. This is the same change feat: require Python 3.11 or later #152 makes, so the two merge without conflict.
  • tests/test_init.py: assert str(x) before x == "...". mypy 1.x no longer reports the line as unreachable, so the type: ignore comments aren't needed, and mypy 2.x has nothing to report as unused.

Testing: I ran pre-commit run --all-files on this branch with default_language_version set to python3.11 and then to python3.14. All 20 hooks pass in both, including prettier with system Node 24.

Earlier testing: I ran the cached hook binaries with --isolated, so no parent ruff config was picked up:

  • ruff 0.16.10 and 0.17.0 check and format: clean
  • mypy 1.18.2 and 2.0.0 with the hook's arguments: clean
  • flake8 7.3.0, pyupgrade 3.21.2: clean
  • pytest: passes. I also added test_primary_device_id. Line 99 changed here and had no test on main, which made codecov/patch fail on the first push.

I also merged this branch onto main together with all 13 open koan PRs. There were no conflicts and 84 tests pass. The only new-ruff finding in the combined tree was a B017 in #142's test, which I fixed on that branch. The exact versions in #131 (ruff 0.17.1, mypy 2.4.0) aren't available offline here, so check #131's run after this merges.

🤖 Generated with Claude Code

pre-commit.ci's autoupdate (Bluetooth-Devices#131) bumps ruff to 0.17 and mypy to 2.4,
which flag code that the pinned versions accept. Its autofix commit
leaves three ruff errors (EXE001, RUF015, PYI018) plus two mypy
unused-ignore errors, and it adds a runtime `from typing import Self`
that raises ImportError on Python 3.9/3.10, which pyproject.toml still
declares as supported.

Fix the code so both the pinned and the updated hook versions pass:
- setup.py: drop the shebang (file is not executable in git)
- docs conf.py: List -> list
- __init__.py: sort __all__
- data.py: next(iter(...)) for primary_device_id; int | float -> float
- enum.py: Self instead of a custom TypeVar, imported only under
  TYPE_CHECKING so runtime stays 3.9-compatible
- test_init.py: assert str() before == so mypy 1.x does not mark the
  line unreachable and mypy 2.x does not flag an unused ignore
@codecov

codecov Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.82%. Comparing base (31bd826) to head (891659d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #153      +/-   ##
==========================================
+ Coverage   94.37%   95.82%   +1.44%     
==========================================
  Files          12       12              
  Lines         480      479       -1     
  Branches        5        5              
==========================================
+ Hits          453      459       +6     
+ Misses         26       18       -8     
- Partials        1        2       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bluetoothbot

Copy link
Copy Markdown
Author

This PR clears the red lint / pre-commit.ci on #131 (the pending pre-commit autoupdate).

On main, #131's new revs fail with:

  • ruff: setup.py:1:1, src/sensor_state_data/data.py:99:20, src/sensor_state_data/enum.py:8:1
  • mypy 2.x: tests/test_init.py:20,25 unused type: ignore

I checked this branch against #131's .pre-commit-config.yaml with ruff 0.17.0 and mypy 2.4.0: ruff passes, and mypy's unused-ignore errors are gone. (#131 pins ruff 0.17.2, which I didn't have cached locally.)

Merging this first should turn #131 green without any other changes.

pyupgrade v3.21.0 calls tokenize.cookie_re.match() on str tokens.
In Python 3.14 that pattern is bytes, so the hook raises TypeError on
any file with a leading comment. pre-commit.ci now runs Python 3.14
by default, which is why it is red on every PR opened since early 2026
while the GitHub Actions lint job (3.11) stays green. Fixed upstream
in 3.21.1; v3.22.0 matches the rev in the pending autoupdate (Bluetooth-Devices#131).
@bluetoothbot bluetoothbot changed the title chore: pass ruff 0.16+ default rules and mypy 2.x chore: fix pre-commit.ci on Python 3.14; pass ruff 0.17 and mypy 2.x Oct 27, 2026

This branch has not been deployed

No deployments
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