fix: watch with no query raises RuntimeError under PEP 479 - #269
Open
VXNCXNX wants to merge 1 commit into
Open
Conversation
Under PEP 479, raise StopIteration in generators becomes RuntimeError.
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.
Description
watchwith no query raisesRuntimeErrorinstead of printing its usage.Same for
watch -candwatch 3, the two other ways to reach the end of the arguments without a statement.watch_queryis a generator, and it ends four of its paths withraise StopIteration. Under PEP 479, which is mandatory from Python 3.7 and this project requires 3.10+, aStopIterationraised inside a generator is converted toRuntimeErrorrather than ending iteration. So the generator yields the usage tuple and then immediately blows up.Replacing each with a bare
returnis the documented fix, and it is what the surrounding code already does implicitly by falling off the end.After, the generator yields the usage row and stops:
and the CLI exits cleanly.
Two of the four are worth calling out because they are not just the no-argument case:
watchKeyboardInterrupthandler, so Ctrl-C during a watch loop hits the sameRuntimeErrorrather than stoppingChecklist
CHANGELOG.mdfile.Testing
test_watch_without_a_query_prints_usageintests/test_special_iocommands.py, parametrised overwatch,watch -candwatch 3, asserting the usage tuple is the only result.Reverting the source fails all three:
pytestis 231 passed, 2 skipped, 1 xfailed, 1 xpassed. CI's pinnedruff==0.11.5reportsAll checks passedand38 files already formatted.One note in case you run a newer ruff locally: latest ruff reports 195 errors on a clean checkout here, including the
PLR1708rule that flags exactly these four lines. Since CI pins 0.11.5 I did not touch anything else it complains about.Disclosure: written with AI assistance (Claude Code). I reproduced the error, ran the before and after and the revert check myself.