8000 feat(python): add an opinionated swallowed-exception guide by LiinaSuoniemi · Pull Request #70 · habit-hooks/habit-hooks · GitHub
[go: up one dir, main page]

Skip to content

feat(python): add an opinionated swallowed-exception guide - #70

Closed
LiinaSuoniemi wants to merge 1 commit into
habit-hooks:v1.0from
LiinaSuoniemi:python-swallowed-exception-guide
Closed

LiinaSuoniemi wants to merge 1 commit into
habit-hooks:v1.0from
LiinaSuoniemi:python-swallowed-exception-guide

Conversation

@LiinaSuoniemi
Copy link
Copy Markdown
Contributor

What this adds

An opinionated Python guide for swallowed-exception (ruff BLE001), so a python config coaches the smell directly. Today a ["python"] config has no guide for it and falls through to the generic default, or to uncoached when generic is not present.

The coaching stance

It coaches the judgment instead of enforcing a blanket rule. Name the specific exception, narrow the catch to it, then make the decision visible. Logging and returning a default is treated as a real option, not automatically a swallow. The check it gives is behavioural: "if this fires at 3am, will anyone know it happened, and why." A swallow is the blind version, a wide catch, nothing named, nothing logged, no trace.

Design notes

  • The guide inlines its own line listing rather than {% include "includes/line_level_issues.md" %}. That include lives in the generic plugin, so a ["python"] config with no generic would crash on it. Inlining keeps the guide self-contained and safe for python-only.
  • It follows the shape of deep-nesting.md: a prose diagnosis, the line listing, a numbered procedure with bold lead-ins, then an anti-gaming closer.

Tests

One new case in habit-mapper.spec.md renders the guide for a python-only swallowed-exception finding (suggested, exits 0). Full python suite green (+1 test, no regressions vs base). The Node and PHP specs that fail in CI are pre-existing and unrelated (the workflow installs Python only).

Note on PR #68

This makes swallowed-exception guided for a python-only config. My other open PR (#68) uses swallowed-exception as its example of an unguided smell, in the case "A python-only config coaches an unguided smell via the core uncoached guide." If both land, that test should switch to another still-unguided python smell such as too-many-parameters. Flagging so the merge order is clear.

Style

Kept the prose tight and dash-free for clarity, happy to match the house em-dash style if you would rather.

Adds a python-owned guide for swallowed-exception (ruff BLE001) so a python config coaches the smell directly instead of falling through to generic or, with no generic, to uncoached. Coaches the judgment (name the exception, narrow the catch, make the decision visible) and treats log-and-return as a valid option, not automatically a swallow. Inlines its line listing rather than the generic include so a python-only config cannot crash on a missing generic. Follows the deep-nesting.md shape. Adds a habit-mapper spec case that renders it for a python-only finding.
@devill
devill commented Jul 1, 2026 •
Copy link
Copy Markdown
Collaborator

Thanks for this, Liina. Two small suggestions before it lands:

  1. Reuse the shared include instead of inlining the listing. {% include "includes/line_level_issues.md" %} keeps it consistent with the other guides. You inlined it because that partial lives in the generic plugin and a python-only config would crash on it — good catch. The cleaner fix is to move the shared partials into the core (the same move fix(mapper): fall back to core baseline guides when generic is dropped #68 makes for clean.md/uncoached.md), so any plugin can use them without generic. Bonus: that also fixes the same latent crash for php-only and typescript-only configs.

  2. Drop the habit-mapper.spec.md case. Those cases run as exact-match tests, so pinning the full guide prose there means every future wording tweak breaks a test — and the routing it checks is already covered by the existing "a finding's language selects a plugin's guide" case.

One ordering note: this overlaps with #68, which uses swallowed-exception as its example of an unguided smell, so we'll land #68 first and adjust that case. I'll cherry-pick your commit onto main with these tweaks so your authorship is preserved. Thank you again for contributing! 🙏

@devill
devill commented Jul 1, 2026
Copy link
Copy Markdown
Collaborator

Merged into main via cherry-pick, so your commit keeps your authorship (f70faea), with a follow-up commit on top (ae7a2b0) applying the two tweaks from the review:

  • switched the guide to the shared {% include "includes/line_level_issues.md" %}, and moved the shared partials into the core so a python-only config resolves them without generic (this also fixed the same latent crash for php-only and typescript-only configs — nice side effect of your find)
  • dropped the exact-match habit-mapper.spec.md case and retargeted fix(mapper): fall back to core baseline guides when generic is dropped #68's fallback case to warning-comment

Landed after #68 and #69, all green. Thank you for the guide — the coaching stance and the "3am" test are genuinely good, and they're in main now. 🙏

@devill
devill commented Jul 1, 2026
Copy link
Copy Markdown
Collaborator

Cherry-picked into main (f70faea + follow-up ae7a2b0). Closing — thank you, Liina!

@devill devill closed this Jul 1, 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.

2 participants

0