Title: agent: structure if-else nesting to avoid duplicated string literals · Issue #1869 · usethis-python/usethis-python · GitHub
Open Graph Title: agent: structure if-else nesting to avoid duplicated string literals · Issue #1869 · usethis-python/usethis-python
X Title: agent: structure if-else nesting to avoid duplicated string literals · Issue #1869 · usethis-python/usethis-python
Description: What happened In uninstall_pre_commit_hooks(), the same info_print message and tick_print message were written twice — once in the uv branch and once in the poetry branch — because the outer if-else branched on the backend, and the share...
Open Graph Description: What happened In uninstall_pre_commit_hooks(), the same info_print message and tick_print message were written twice — once in the uv branch and once in the poetry branch — because the outer if-els...
X Description: What happened In uninstall_pre_commit_hooks(), the same info_print message and tick_print message were written twice — once in the uv branch and once in the poetry branch — because the outer if-els...
Opengraph URL: https://github.com/usethis-python/usethis-python/issues/1869
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"agent: structure if-else nesting to avoid duplicated string literals","articleBody":"## What happened\n\nIn `uninstall_pre_commit_hooks()`, the same `info_print` message and `tick_print` message were written twice — once in the `uv` branch and once in the `poetry` branch — because the outer if-else branched on the backend, and the shared guard condition (`_is_git_repo()`) was nested separately inside each arm.\n\n## Root cause\n\nWhen a guard condition (like \"is git available?\") applies equally to multiple branches of an outer if-else, nesting it inside each branch independently leads to duplicated code. The duplication was introduced because the backend dispatch was written at the outer level first, making each arm independently responsible for its own guard logic.\n\n## Generalised principle\n\nWhen a guard condition applies to a *group* of branches (e.g. multiple enum values), always check that guard at the outer level — using a combined membership check such as `if backend in (A, B):` — before branching on individual values. Nesting shared conditions inside each branch individually causes string and logic duplication that is easy to miss and hard to keep in sync. If you notice the same string literal or logic block appearing in two sibling branches of an if-else, treat that as a signal to restructure: hoist the shared condition to the outer level, and move the distinguishing logic to the inner level.\n\n## Resolution\n\nRefactored `uninstall_pre_commit_hooks()` to first check `backend in (BackendEnum.uv, BackendEnum.poetry)`, then check `_is_git_repo()` once in that outer block, then branch on the specific backend for the differing uninstall logic. The duplicated `info_print` and `tick_print` messages were each reduced to a single occurrence.\n\n## Follow-up\n\nNone.","author":{"url":"https://github.com/nathanjmcdougall","@type":"Person","name":"nathanjmcdougall"},"datePublished":"2026-04-07T18:53:05.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/1869/usethis-python/issues/1869"}
| 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:61761922-a843-aeb6-3c5a-9c19c2bd0e9e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 875C:333592:5984CF:81DE37:6A4E09EC |
| html-safe-nonce | 4f1d90ad848a8c1329345e7472dfb72a651ad3df08cd1dcccdba8cbc4d43f6b2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NzVDOjMzMzU5Mjo1OTg0Q0Y6ODFERTM3OjZBNEUwOUVDIiwidmlzaXRvcl9pZCI6Ijc4NzEwNjExOTQ0OTE4NDc0OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6404028f255b6eca24a45397715411cf5e92fc1f3ed66fdb99309f9a554ec75f |
| hovercard-subject-tag | issue:4219911941 |
| 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/1869/issue_layout |
| twitter:image | https://opengraph.githubassets.com/454c8cf5f5e56b778eb0ed1f0ddee2207f8cdd6367ea12808b935172c6e2004a/usethis-python/usethis-python/issues/1869 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/454c8cf5f5e56b778eb0ed1f0ddee2207f8cdd6367ea12808b935172c6e2004a/usethis-python/usethis-python/issues/1869 |
| og:image:alt | What happened In uninstall_pre_commit_hooks(), the same info_print message and tick_print message were written twice — once in the uv branch and once in the poetry branch — because the outer if-els... |
| 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 | df0492960db29b4938cb72070351d6b1d0c6c0767b27ceb8394bbf4fcc0223c6 |
| 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 | 51470c353b8a1f52a88d3e3cc2014b17ab8cc1ce |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width