Skip to content

fix: watch with no query raises RuntimeError under PEP 479 - #269

Open
VXNCXNX wants to merge 1 commit into
dbcli:mainfrom
VXNCXNX:fix-watch-stopiteration
Open

fix: watch with no query raises RuntimeError under PEP 479#269
VXNCXNX wants to merge 1 commit into
dbcli:mainfrom
VXNCXNX:fix-watch-stopiteration

Conversation

@VXNCXNX

@VXNCXNX VXNCXNX commented Aug 15, 2026

Copy link
Copy Markdown

Description

watch with no query raises RuntimeError instead of printing its usage.

$ litecli -e 'watch' :memory:
generator raised StopIteration

Same for watch -c and watch 3, the two other ways to reach the end of the arguments without a statement.

watch_query is a generator, and it ends four of its paths with raise StopIteration. Under PEP 479, which is mandatory from Python 3.7 and this project requires 3.10+, a StopIteration raised inside a generator is converted to RuntimeError rather than ending iteration. So the generator yields the usage tuple and then immediately blows up.

Replacing each with a bare return is 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:

$ python -c "from litecli.packages.special.iocommands import watch_query; print(len(list(watch_query(''))))"
1

and the CLI exits cleanly.

Two of the four are worth calling out because they are not just the no-argument case:

  • the "Wise choice!" branch, reached by answering no to a destructive-query confirmation inside watch
  • the KeyboardInterrupt handler, so Ctrl-C during a watch loop hits the same RuntimeError rather than stopping

Checklist

  • I've added this contribution to the CHANGELOG.md file.

Testing

test_watch_without_a_query_prints_usage in tests/test_special_iocommands.py, parametrised over watch, watch -c and watch 3, asserting the usage tuple is the only result.

Reverting the source fails all three:

E   RuntimeError: generator raised StopIteration
FAILED tests/test_special_iocommands.py::test_watch_without_a_query_prints_usage[watch]
FAILED ...[watch -c]
FAILED ...[watch 3]

pytest is 231 passed, 2 skipped, 1 xfailed, 1 xpassed. CI's pinned ruff==0.11.5 reports All checks passed and 38 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 PLR1708 rule 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.

Under PEP 479, raise StopIteration in generators becomes RuntimeError.
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