Skip to content

refactor: declare BaseAction's REPR_FIELDS and NAME as ClassVar - #680

Merged
mergify[bot] merged 2 commits into
mainfrom
devs/jd/chore/mypy-strictness/declare-baseaction-s-repr-fields-name-classvar--012caeaa
Aug 5, 2026
Merged

refactor: declare BaseAction's REPR_FIELDS and NAME as ClassVar#680
mergify[bot] merged 2 commits into
mainfrom
devs/jd/chore/mypy-strictness/declare-baseaction-s-repr-fields-name-classvar--012caeaa

Conversation

@jd

@jd jd commented Aug 5, 2026

Copy link
Copy Markdown
Owner

mutable-override rejects narrowing a mutable attribute in a subclass:
RetryAction.REPR_FIELDS = ("sleep",) inferred tuple[str] against the
base's Sequence[str], and NAME = "retry" inferred str against
str | None. Both are unsound in general -- code holding a BaseAction
could assign a longer sequence or None through the base type.

BaseAction's docstring already calls these class variables, so mark them
ClassVar and repeat the base annotation on the override. This documents
the extension point for subclasses outside tenacity too, which hit the
same error when they type check strictly.

Depends-On: #679

@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 refactor: drop always-true truthiness checks and enable truthy-bool #679
2 refactor: declare BaseAction's REPR_FIELDS and NAME as ClassVar #680 👈
3 test: fix possibly-undefined and deprecated call sites #681
4 refactor: mark overridden methods with @OverRide #682

@jd
jd marked this pull request as ready for review August 5, 2026 15:34
@jd
jd force-pushed the devs/jd/chore/mypy-strictness/drop-always-true-truthiness-checks-enable-truthy--cb9981f6 branch from 05deb5e to 7229e61 Compare August 5, 2026 15:39
@jd
jd force-pushed the devs/jd/chore/mypy-strictness/declare-baseaction-s-repr-fields-name-classvar--012caeaa branch from 83a4c19 to 227f834 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 83a4c19 2026-08-05 15:39 UTC
2 rebase 83a4c19 → 227f834 (rebase only) 2026-08-05 15:39 UTC
3 rebase 227f834 → 4fc0664 (rebase only) 2026-08-05 15:47 UTC

@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 227f834b2057fe1623fe8647a6967576bad3d243

This pull request spent 1 minute 56 seconds in the queue, including 10 seconds running CI.

Waiting for
All conditions

Reason

Pull request #680 has been dequeued

Queue conditions are not satisfied:

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:45
`truthy-bool` reports objects tested for truthiness that implement neither
`__bool__` nor `__len__`, and so can only ever be true. Three sites:

`BaseRetrying._run_wait` and `AsyncRetrying._run_wait` both guarded the
wait call with `if self.wait:`. `wait` is typed `WaitBaseT` and defaults to
a `wait_none()` instance, so it is never falsy and the `sleep = 0.0` branch
has been dead since 17aefd9 -- a leftover from when the surrounding code
still used `if self.after is not None:` style guards. Call `self.wait`
unconditionally.

`if tornado:` guarded the optional import in two places. mypy only ever
sees the `try` branch, so it resolves the name to the module and reads the
test as always-true. Compute `_HAS_TORNADO` once and branch on that
instead; this also keeps `tornado.gen` fully typed, which annotating the
name as `ModuleType | None` would have thrown away.

Change-Id: Icb9981f6797707e070dc2423015f2fbf6c94e4c4
`mutable-override` rejects narrowing a mutable attribute in a subclass:
`RetryAction.REPR_FIELDS = ("sleep",)` inferred `tuple[str]` against the
base's `Sequence[str]`, and `NAME = "retry"` inferred `str` against
`str | None`. Both are unsound in general -- code holding a `BaseAction`
could assign a longer sequence or `None` through the base type.

`BaseAction`'s docstring already calls these class variables, so mark them
`ClassVar` and repeat the base annotation on the override. This documents
the extension point for subclasses outside tenacity too, which hit the
same error when they type check strictly.

Change-Id: I012caeaad2f93327c69467776a53e87c573b6403
@jd
jd force-pushed the devs/jd/chore/mypy-strictness/drop-always-true-truthiness-checks-enable-truthy--cb9981f6 branch from 7229e61 to 220001e Compare August 5, 2026 15:47
@jd
jd force-pushed the devs/jd/chore/mypy-strictness/declare-baseaction-s-repr-fields-name-classvar--012caeaa branch from 227f834 to 4fc0664 Compare August 5, 2026 15:47
@mergify mergify Bot removed the dequeued label Aug 5, 2026
Base automatically changed from devs/jd/chore/mypy-strictness/drop-always-true-truthiness-checks-enable-truthy--cb9981f6 to main August 5, 2026 15:48
@mergify

mergify Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

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

Required conditions to merge

@mergify
mergify Bot merged commit d6690dc into main Aug 5, 2026
9 of 16 checks passed
@mergify
mergify Bot deleted the devs/jd/chore/mypy-strictness/declare-baseaction-s-repr-fields-name-classvar--012caeaa branch August 5, 2026 15:49
@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