Title: fix: wrap `yield` in `try-finally` in `UsethisConfig.set()` and `change_cwd()` by Copilot · Pull Request #1834 · usethis-python/usethis-python · GitHub
Open Graph Title: fix: wrap `yield` in `try-finally` in `UsethisConfig.set()` and `change_cwd()` by Copilot · Pull Request #1834 · usethis-python/usethis-python
X Title: fix: wrap `yield` in `try-finally` in `UsethisConfig.set()` and `change_cwd()` by Copilot · Pull Request #1834 · usethis-python/usethis-python
Description: @contextmanager cleanup code placed after yield doesn't execute on exception — the exception re-raises at the yield point, skipping everything below it. This left usethis_config in a corrupted state (e.g. quiet=True permanently) when exceptions propagated through with usethis_config.set(...) blocks. Changes src/usethis/_config.py — Wrap yield in try-finally in UsethisConfig.set() so _restore() always runs src/usethis/_test.py — Same fix for change_cwd() so os.chdir(old_dir) always runs tests/usethis/test_config.py — Add tests verifying state restoration after exception .agents/skills/usethis-python-code/SKILL.md — Add this as a documented common mistake in the context manager guidance (v1.9) # Before: cleanup skipped on exception self.project_dir = project_dir yield self._restore(old) # never reached if body raises # After: cleanup guaranteed self.project_dir = project_dir try: yield finally: self._restore(old)
Open Graph Description: @contextmanager cleanup code placed after yield doesn't execute on exception — the exception re-raises at the yield point, skipping everything below it. This left usethis_config in a corrupted ...
X Description: @contextmanager cleanup code placed after yield doesn't execute on exception — the exception re-raises at the yield point, skipping everything below it. This left usethis_config in a corrup...
Opengraph URL: https://github.com/usethis-python/usethis-python/pull/1834
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:5a0b4e19-e0fd-da54-8f7b-e9c0c42de3ae |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9F42:35ABFC:EA0459:149DB91:6A4CAF20 |
| html-safe-nonce | 4a867b7929d97fbfe7e5f99760b9bd3a423c7423f0b8f1f85ae597957aa28102 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RjQyOjM1QUJGQzpFQTA0NTk6MTQ5REI5MTo2QTRDQUYyMCIsInZpc2l0b3JfaWQiOiI2NTQzOTI5MjU0Nzc3NDk5NDI0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 49fdff4e4987e0ec9582962affc0c16427aa1bd165e9abae61df2bfc256eeda7 |
| hovercard-subject-tag | pull_request:3495837554 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/usethis-python/usethis-python/pull/1834/files |
| twitter:image | https://avatars.githubusercontent.com/in/1143301?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/in/1143301?s=400&v=4 |
| og:image:alt | @contextmanager cleanup code placed after yield doesn't execute on exception — the exception re-raises at the yield point, skipping everything below it. This left usethis_config in a corrupted ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3d11bb817438277de2a940854450e83a7d32b6aeb5014e9e6b00a6423900251c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ae90d426644ca15e89bacceb72e51f4e9dbf85f7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width