Title: fix(util): tolerate deleted temporary environment variables by Abedyn · Pull Request #2340 · gitpython-developers/GitPython · GitHub
Open Graph Title: fix(util): tolerate deleted temporary environment variables by Abedyn · Pull Request #2340 · gitpython-developers/GitPython
X Title: fix(util): tolerate deleted temporary environment variables by Abedyn · Pull Request #2340 · gitpython-developers/GitPython
Description: patch_env() raises KeyError on exit if its variable was originally absent and the context body deletes it. If the body also raises an exception, the cleanup error masks that exception. Use os.environ.pop(name, None) when restoring an originally absent variable. Add 18 regression cases covering absent, empty and populated original values; unchanged, replaced and deleted temporary values; and normal and exceptional exits. Motivation: this was discovered while inspecting GitPython with a user seeking their first small Python contribution to Git tooling on Windows. The goal is to make the environment helper's restoration behavior consistent when a caller changes the temporary variable. Codex prepared the implementation, tests and this description. Validation on Windows, Python 3.13.17 and Git 2.56.0.windows.4: Before the fix: 2 failed, 16 passed. After the fix: 18 passed with GIT_PYTHON_BACKEND=cli and python -m pytest --noconftest -o addopts='' test/test_patch_env.py -q --tb=short. Ruff lint and formatting checks passed for both changed files; git diff --check passed. The full suite and its conftest hooks were not run. Installing the test extra with binary-only GixPython failed because no compatible Windows wheel for GixPython 0.3.0 was available. The focused tests do not use repository fixtures or Gix.
Open Graph Description: patch_env() raises KeyError on exit if its variable was originally absent and the context body deletes it. If the body also raises an exception, the cleanup error masks that exception. Use os.envir...
X Description: patch_env() raises KeyError on exit if its variable was originally absent and the context body deletes it. If the body also raises an exception, the cleanup error masks that exception. Use os.envir...
Opengraph URL: https://github.com/gitpython-developers/GitPython/pull/2340
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:626b71ef-5a02-6ed5-74b2-b41b3a127712 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 8C98:28815B:1CDE4F:274832:6B00BF4E |
| html-safe-nonce | a694db2199e1858867226cec3e9cf74f8484f0feaba2c1373f9f3ae4981329b2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Qzk4OjI4ODE1QjoxQ0RFNEY6Mjc0ODMyOjZCMDBCRjRFIiwidmlzaXRvcl9pZCI6IjM0NzAwNTQ3MjA4OTM1ODE1OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4f5d4f901b341ee17f73f165582816e42a08bd65046ed1279beca92ea8315185 |
| hovercard-subject-tag | pull_request:5157566969 |
| 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/gitpython-developers/GitPython/pull/2340/files |
| twitter:image | https://avatars.githubusercontent.com/u/168976722?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/168976722?s=400&v=4 |
| og:image:alt | patch_env() raises KeyError on exit if its variable was originally absent and the context body deletes it. If the body also raises an exception, the cleanup error masks that exception. Use os.envir... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 93edd3bebc4afb7ce711ee74cb5d2a95927850b082a4d43e212222389cb1c415 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/gitpython-developers/GitPython git https://github.com/gitpython-developers/GitPython.git |
| octolytics-dimension-user_id | 503709 |
| octolytics-dimension-user_login | gitpython-developers |
| octolytics-dimension-repository_id | 1126087 |
| octolytics-dimension-repository_nwo | gitpython-developers/GitPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1126087 |
| octolytics-dimension-repository_network_root_nwo | gitpython-developers/GitPython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 1fee81a280ea86312b69448e261b418189bfd5b5 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width