Title: agent: keep enum-based if-statements at the innermost nesting level · Issue #1870 · usethis-python/usethis-python · GitHub
Open Graph Title: agent: keep enum-based if-statements at the innermost nesting level · Issue #1870 · usethis-python/usethis-python
X Title: agent: keep enum-based if-statements at the innermost nesting level · Issue #1870 · usethis-python/usethis-python
Description: What happened In uninstall_pre_commit_hooks(), the dispatch over backend enum values was at the outer level of nesting. Guard conditions that applied to multiple backends (specifically _is_git_repo()) were then nested inside each backend...
Open Graph Description: What happened In uninstall_pre_commit_hooks(), the dispatch over backend enum values was at the outer level of nesting. Guard conditions that applied to multiple backends (specifically _is_git_repo...
X Description: What happened In uninstall_pre_commit_hooks(), the dispatch over backend enum values was at the outer level of nesting. Guard conditions that applied to multiple backends (specifically _is_git_repo...
Opengraph URL: https://github.com/usethis-python/usethis-python/issues/1870
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"agent: keep enum-based if-statements at the innermost nesting level","articleBody":"## What happened\n\nIn `uninstall_pre_commit_hooks()`, the dispatch over backend enum values was at the *outer* level of nesting. Guard conditions that applied to multiple backends (specifically `_is_git_repo()`) were then nested *inside* each backend arm, causing them to be repeated. The correct structure — outer guard, inner enum dispatch — was already used in the sibling function `install_pre_commit_hooks()`, but the pattern was not carried over consistently.\n\n## Root cause\n\nWhen writing code that dispatches on an enum, it is natural to start with the enum branches at the outermost level. But additional cross-cutting concerns (like \"is git available?\") then get added inside each branch, leading to duplication. The root cause is treating enum dispatch as always the right outermost axis, regardless of whether other conditions apply more broadly.\n\n## Generalised principle\n\nEnum-based if-statements (dispatching on a finite set of known values) should be kept at the *innermost* level of nesting when other conditions apply to a group of those enum values. Outer conditions should narrow down the context; inner enum dispatch should then select the specific behaviour. If an enum dispatch is at the outer level and you find yourself repeating the same guard inside multiple arms, that is a reliable signal that the nesting levels are inverted. Swap them: put the shared guard outer, and the enum dispatch inner.\n\n## Resolution\n\nRefactored `uninstall_pre_commit_hooks()` so that `backend in (BackendEnum.uv, BackendEnum.poetry)` is the outer check, the `_is_git_repo()` guard sits once inside that block, and the per-backend enum dispatch (`if backend is BackendEnum.uv / elif backend is BackendEnum.poetry`) sits at the innermost level.\n\n## Follow-up\n\nNone.","author":{"url":"https://github.com/nathanjmcdougall","@type":"Person","name":"nathanjmcdougall"},"datePublished":"2026-04-07T18:53:22.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/1870/usethis-python/issues/1870"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:bedf38c0-121d-1d2e-c675-097d2aab6893 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A8E6:6456C:12D69CD:19F746D:6A4DE115 |
| html-safe-nonce | 8023c5adc65cfe00dd1d7cb00d3e4012536322f7fea5d347d10e6e0602e64ab3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOEU2OjY0NTZDOjEyRDY5Q0Q6MTlGNzQ2RDo2QTRERTExNSIsInZpc2l0b3JfaWQiOiIyMDcyMjI4MTc3NzE1NzgxOTA5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 4dccb8f29be409c23f26093241e76f5235f8e132cadb4ffed8d9d63087f2c2ad |
| hovercard-subject-tag | issue:4219913103 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/usethis-python/usethis-python/1870/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c9b2227003e6705eb3009b9f5cae0476342fd9464fc6e059630baf5a8cd3f7fd/usethis-python/usethis-python/issues/1870 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c9b2227003e6705eb3009b9f5cae0476342fd9464fc6e059630baf5a8cd3f7fd/usethis-python/usethis-python/issues/1870 |
| og:image:alt | What happened In uninstall_pre_commit_hooks(), the dispatch over backend enum values was at the outer level of nesting. Guard conditions that applied to multiple backends (specifically _is_git_repo... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nathanjmcdougall |
| hostname | github.com |
| expected-hostname | github.com |
| None | 06b8a6144231bf3a234f1c2e9993861e07ce98a905912b114aa386c2d7e84b33 |
| turbo-cache-control | no-preview |
| go-import | github.com/usethis-python/usethis-python git https://github.com/usethis-python/usethis-python.git |
| octolytics-dimension-user_id | 216362695 |
| octolytics-dimension-user_login | usethis-python |
| octolytics-dimension-repository_id | 842189705 |
| octolytics-dimension-repository_nwo | usethis-python/usethis-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 842189705 |
| octolytics-dimension-repository_network_root_nwo | usethis-python/usethis-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 1d344bdb7547fe6bca17a59bb2b8aac3dc9532a0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width