Skip to content

refactor: mark overridden methods with @override - #682

Merged
mergify[bot] merged 2 commits into
mainfrom
devs/jd/chore/mypy-strictness/mark-overridden-methods-override--de71dd20
Aug 5, 2026
Merged

refactor: mark overridden methods with @override#682
mergify[bot] merged 2 commits into
mainfrom
devs/jd/chore/mypy-strictness/mark-overridden-methods-override--de71dd20

Conversation

@jd

@jd jd commented Aug 5, 2026

Copy link
Copy Markdown
Owner

explicit-override is off under strict, and 63 methods across the
library and tests were overriding a base method without saying so. That
makes a whole class of change silently lossy: rename or drop a method on
retry_base/wait_base/stop_base/BaseRetrying and every subclass keeps
its now-orphaned implementation, still importable, never called again.

typing.override only exists from Python 3.12, and tenacity has no runtime
dependencies, so _utils imports it from typing_extensions under
TYPE_CHECKING (as the module already does for Self) and falls back to a
small PEP 698 shim at runtime on 3.10/3.11. Type checkers only ever see the
typing_extensions name, so the check works regardless of the interpreter
mypy runs under.

That last point exposed a second problem worth fixing here: mypy's
python_version defaults to whatever interpreter runs it, so CI on 3.14 was
never verifying that the code is valid on the 3.10 we claim to support. Pin
python_version = "3.10" to match requires-python. It caught one real
case immediately -- RetryCallState.__getstate__ is only an override from
3.11 on, where object.__getstate__ was introduced, so it must not carry
the decorator.

Verified mypy reports the same result under both a 3.10 and a 3.14
interpreter, and the runtime shim sets __override__ correctly on 3.10.

Depends-On: #681

@jd

jd commented Aug 5, 2026

Copy link
Copy Markdown
Owner Author

This pull request is part of a Mergify stack:

# Pull Request Link
1 test: fix possibly-undefined and deprecated call sites #681
2 refactor: mark overridden methods with @OverRide #682 👈

@jd
jd marked this pull request as ready for review August 5, 2026 15:36
@jd
jd force-pushed the devs/jd/chore/mypy-strictness/fix-possibly-undefined-deprecated-call-sites--135cf536 branch from cdd9c7b to dbf3491 Compare August 5, 2026 15:39
@jd
jd force-pushed the devs/jd/chore/mypy-strictness/mark-overridden-methods-override--de71dd20 branch from 0ef3a14 to 73f02ad Compare August 5, 2026 15:39
@jd

jd commented Aug 5, 2026

Copy link
Copy Markdown
Owner Author

Revision history

# Type Changes Reason Date
1 initial 0ef3a14 2026-08-05 15:39 UTC
2 rebase 0ef3a14 → 73f02ad (rebase only) 2026-08-05 15:39 UTC
3 rebase 73f02ad → 8c5a928 (rebase only) 2026-08-05 15:47 UTC
4 rebase 8c5a928 → c5fa908 (rebase only) 2026-08-05 15:59 UTC

@mergify mergify Bot added the queued label Aug 5, 2026
@mergify

mergify Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • Entered queue2026-08-05 15:41 UTC · Rule: default · triggered by rule autoqueue
  • Checks skipped · PR is already up-to-date
  • 🚫 Left the queue2026-08-05 15:43 UTC · at 73f02ad7ce5a13d9b7346d3034494376248f4995

This pull request spent 2 minutes 3 seconds in the queue, including 9 seconds running CI.

Waiting for
All conditions

Reason

Pull request #682 has been dequeued

queue conditions no longer match. Blocked by:

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Requeued — the merge queue status continues in this comment ↓.

@mergify mergify Bot added dequeued and removed queued labels Aug 5, 2026
@jd
jd force-pushed the devs/jd/chore/mypy-strictness/fix-possibly-undefined-deprecated-call-sites--135cf536 branch from dbf3491 to dc1546e Compare August 5, 2026 15:47
@jd
jd force-pushed the devs/jd/chore/mypy-strictness/mark-overridden-methods-override--de71dd20 branch from 73f02ad to 8c5a928 Compare August 5, 2026 15:47
@mergify mergify Bot removed the dequeued label Aug 5, 2026
@mergify

mergify Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • Entered queue2026-08-05 15:48 UTC · Rule: default · triggered by rule autoqueue
  • Checks skipped · PR is already up-to-date
  • 🚫 Left the queue2026-08-05 15:49 UTC · at 8c5a92833ff28140c3b9e91e99e7eceb8bfd4a0b

This pull request spent 1 minute 7 seconds in the queue, including 4 seconds running CI.

Waiting for
All conditions

Reason

Pull request #682 has been dequeued

queue conditions no longer match. Blocked by:

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Requeued — the merge queue status continues in this comment ↓.

jd added 2 commits August 5, 2026 17:58
Two more error codes mypy leaves off under `strict`, both with real hits
in the test suite.

`possibly-undefined`: `test_retry_state` bound `retry_state` only inside
an `except ExtractCallState` block, then used it unconditionally. Had the
retry stopped raising, the test would have failed with `NameError` instead
of a useful assertion. Use `assertRaises` as a context manager, which both
asserts the exception is raised and binds the state unconditionally.

`deprecated`: `asyncio.iscoroutinefunction` is deprecated since 3.14 and
removed in 3.16, and was emitting a `DeprecationWarning` on every test run.
The line right below it already asserts the same property via
`inspect.iscoroutinefunction`, which is the documented replacement, so drop
the deprecated call rather than pin the suite to an API that is going away.

Change-Id: I135cf5364f3e471d954c878f2599be7441104971
`explicit-override` is off under `strict`, and 63 methods across the
library and tests were overriding a base method without saying so. That
makes a whole class of change silently lossy: rename or drop a method on
`retry_base`/`wait_base`/`stop_base`/`BaseRetrying` and every subclass keeps
its now-orphaned implementation, still importable, never called again.

`typing.override` only exists from Python 3.12, and tenacity has no runtime
dependencies, so `_utils` imports it from `typing_extensions` under
TYPE_CHECKING (as the module already does for `Self`) and falls back to a
small PEP 698 shim at runtime on 3.10/3.11. Type checkers only ever see the
`typing_extensions` name, so the check works regardless of the interpreter
mypy runs under.

That last point exposed a second problem worth fixing here: mypy's
`python_version` defaults to whatever interpreter runs it, so CI on 3.14 was
never verifying that the code is valid on the 3.10 we claim to support. Pin
`python_version = "3.10"` to match `requires-python`. It caught one real
case immediately -- `RetryCallState.__getstate__` is only an override from
3.11 on, where `object.__getstate__` was introduced, so it must not carry
the decorator.

Verified `mypy` reports the same result under both a 3.10 and a 3.14
interpreter, and the runtime shim sets `__override__` correctly on 3.10.

Change-Id: Ide71dd204215e82012f6a9b1afc725dd7c5db8ee
@jd
jd force-pushed the devs/jd/chore/mypy-strictness/mark-overridden-methods-override--de71dd20 branch from 8c5a928 to c5fa908 Compare August 5, 2026 15:59
@jd
jd force-pushed the devs/jd/chore/mypy-strictness/fix-possibly-undefined-deprecated-call-sites--135cf536 branch from dc1546e to d245e46 Compare August 5, 2026 15:59
@mergify mergify Bot removed the dequeued label Aug 5, 2026
Base automatically changed from devs/jd/chore/mypy-strictness/fix-possibly-undefined-deprecated-call-sites--135cf536 to main August 5, 2026 16:00
@mergify mergify Bot added the queued label Aug 5, 2026
@mergify

mergify Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 30 seconds in the queue, including 2 seconds running CI.

Required conditions to merge

@mergify
mergify Bot merged commit a099996 into main Aug 5, 2026
9 of 16 checks passed
@mergify
mergify Bot deleted the devs/jd/chore/mypy-strictness/mark-overridden-methods-override--de71dd20 branch August 5, 2026 16:01
@mergify mergify Bot removed the queued label Aug 5, 2026
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