Title: Fix TemporaryFileSwap regression where file_path could not be Path by EliahKagan · Pull Request #1776 · gitpython-developers/GitPython · GitHub
Open Graph Title: Fix TemporaryFileSwap regression where file_path could not be Path by EliahKagan · Pull Request #1776 · gitpython-developers/GitPython
X Title: Fix TemporaryFileSwap regression where file_path could not be Path by EliahKagan · Pull Request #1776 · gitpython-developers/GitPython
Description: As noted in #1770 (comment), in 9e86053 (#1770) I accidentally introduced a regression in git.index.util.TemporaryFileSwap where the file_path parameter could no longer be a Path, even though it was (and remained) annotated in a way compatible with that. Passing a Path object instead of str failed with TypeError, with a message like this (with WindowsPath instead of PosixPath on Windows, but otherwise the same): TypeError: unsupported operand type(s) for +: 'PosixPath' and 'str' Although much code that results in TemporaryFileSwap being used is under test, which would reveal some kinds of regressions, TemporaryFileSwap itself did not have any tests. It is public, so even if a Path were never passed to it in GitPython's own use of it, applications that use GitPython may be making direct use of it and are justified in assuming it accepts both a str and a str-based Path, as annotated. This pull request: Adds a general test of TemporaryFileSwap. It does not test every code path that is supposed to be supported, such as code paths involving the file not existing in the first place, or the temporary file being deleted before it would be swapped back (those are deliberately covered in the code and may thus be valuable to test, and perhaps I, or someone else, could add tests for that later). However, I parameterized the test by the type of the file_path argument passed to TemporaryFileSwap, and the test shows both that it works when the type is str and that it fails, as described above, when the type is Path. Fixes the bug, and also changes how mkstemp is called to make it less unidiomatic. (However, it is still opening the file to reserve its name, and then immediately closing it, so this does not address the original misgivings noted in #1770 (review). See my comment in that review thread.) There are some further details, which I'd consider less essential but potentially of value, in the commit messages.
Open Graph Description: As noted in #1770 (comment), in 9e86053 (#1770) I accidentally introduced a regression in git.index.util.TemporaryFileSwap where the file_path parameter could no longer be a Path, even though it wa...
X Description: As noted in #1770 (comment), in 9e86053 (#1770) I accidentally introduced a regression in git.index.util.TemporaryFileSwap where the file_path parameter could no longer be a Path, even though it wa...
Opengraph URL: https://github.com/gitpython-developers/GitPython/pull/1776
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:39d0bbd4-104d-fa28-d075-a53714e13f2f |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | DBDC:22008D:7F1F24:B1CB53:696907B6 |
| html-safe-nonce | 45550ec54edc26c4a2530b83b770cd0bb81ea8ad87c4193afc5589a342d586a7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQkRDOjIyMDA4RDo3RjFGMjQ6QjFDQjUzOjY5NjkwN0I2IiwidmlzaXRvcl9pZCI6IjQxODY2MzExODQ0MjgxMDc3MDIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2cf608595c6444c7a3e627461596bcabfacb4bf31b7fd617d4fed41d95828955 |
| hovercard-subject-tag | pull_request:1653122702 |
| 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/1776/files |
| twitter:image | https://avatars.githubusercontent.com/u/1771172?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/1771172?s=400&v=4 |
| og:image:alt | As noted in #1770 (comment), in 9e86053 (#1770) I accidentally introduced a regression in git.index.util.TemporaryFileSwap where the file_path parameter could no longer be a Path, even though it wa... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | e6156bd4ef9f2dc8dadf4c49a8f7ed8532186388cef72eda3ccb9f0ab3b8cfca |
| 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 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 | ee2210c3e58153aae53400c942f8a7b4bbb43ec4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width