Skip to content

Rewrite lifecycle.py for legibility, and make every hook return a string - #20

Merged
nigelgilbert merged 15 commits into
mainfrom
chore/pythonic-meditations-1
Nov 22, 2026
Merged

nigelgilbert merged 15 commits into
mainfrom
chore/pythonic-meditations-1

Conversation

@nigelgilbert

@nigelgilbert nigelgilbert commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

lifecycle.py is rewritten to read top to bottom, following a short set of Python style rules that are now in the repo. The branch also carries #23, which changes what a hook must return.

For existing hook files

Every hook now returns a string. Returning None, or nothing, used to mean "leave it as it was". Now it fails like any other hook failure:

on_cleaned in voice.py: TypeError: on_cleaned returned NoneType, not str
  • Text hooks (on_transcribed, on_cleaned, on_sent): add return t to change nothing. "" still stops the dictation.
  • on_done: also returns t. The return is not used, but it is checked.
  • on_error: return e to pass to the next on_error hook, or to the default message when none is left. A string is still the message and "" still means no message. A hook that returns None is skipped and its failure goes in errors.txt.

What changed

  • Style rules: docs/pythonic.md holds seven Python style rules, and a new CLAUDE.md points agents at them.
  • lifecycle.py: helpers now come first, names are clearer, every function has a docstring, and long expressions are split into one step per line. on_done and on_error each get their own function, so fire and report have no special cases.
  • Hook returns: every hook must return a string, as described above.
  • Logging: both modules log under their own names instead of uvicorn's. Errors still go to stderr, now in Python's default format.
  • Docs, examples and tests: updated for the new return rules.

Checks

In sidecar/: pytest 103 passed, pyright 0 errors, ruff check and ruff format --check clean.

@nigelgilbert nigelgilbert changed the title Chore/pythonic meditations 1 Rewrite lifecycle.py for legibility, and make every hook return a string Nov 22, 2026
@nigelgilbert
nigelgilbert marked this pull request as ready for review November 22, 2026 20:31
@nigelgilbert
nigelgilbert merged commit 63dddba into main Nov 22, 2026
1 check passed
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