Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 965
Respect os.Pathlike#2086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Respect os.Pathlike#2086
Conversation
36bd3ba to 5d26325CompareGeorge-Ogden commented Nov 27, 2025
Also, I notice you skip mypy because it produces errors. Why not pin the version and increment it periodically? |
Byron commented Nov 28, 2025
That's a great incentive, thanks so much! Using
I don't see why this wouldn't work, great idea! Please feel free to set this up in your next PR :). |
Byron commented Nov 28, 2025
It seems that I won't get my copilot review here, so I wonder why you'd not be calling |
George-Ogden commented Nov 28, 2025
|
George-Ogden commented Nov 28, 2025
Sure thing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Byron left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks better indeed.
Something I think will be desirable is to actually add tests for non-decodable paths for the functions/types that are affected. Otherwise, how do we know it's working?
Feel free to use AI for that, it's quite good at this usually.
The idea is to prove that the changes actually make something possible that wasn't possible before.
| # When pathlib.Path or other class-based path is passed | ||
| ifnotisinstance(path, str): | ||
| path=str(path) | ||
| url=os.fspath(url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URL is not a path though.
George-OgdenNov 29, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, url can be a path if you're cloning a local repo, and if it's not os.fspath will leave strings alone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Copilot <[email protected]>
Byron left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's great, thanks a lot!
What should be shown in the tests is that it can now handle filepaths that don't decode with the standard encoding.
Candidate tests are:
- clone from a filesystem path
index.addwith a strange path- and probably more - you could intentionally break a piece of code that changed
fspathand see which tests fail, then it's clear where to add a test with a 'special' path.
Thanks for making this happen, and thanks for your understanding - we can't just make changes hoping it will work or doesn't make things work, but there must be real evidence that this is desirable. And we can only have that with tests that fail without this change.
Uh oh!
There was an error while loading. Please reload this page.
b45854a to 15f985bCompare15f985b to 8434967CompareByron commented Nov 30, 2025
I am putting the PR back to draft until there are tests that use the new "can handle paths encoding independently from the runtime encoding" to prove the changes are effective. Thanks again. |
George-Ogden commented Nov 30, 2025
Sorry, I meant to add this comment with the changes I made yesterday: For example, the |
Byron commented Dec 1, 2025
No problem! What I mean is that the point of this conversion is to prevent decoding issues related to paths. I.e. the user passes a filesystem path, but internally GitPython runs You'd have to go back to |
George-Ogden commented Dec 1, 2025
I've added some non-ASCII characters into the tests. However, the main point of the pull request is with objects that follow the importosfromdataclassesimportdataclass@dataclassclassCustomPathlike: path: strdef__fspath__(self) ->str: returnself.pathcustom_pathlike=CustomPathlike("folder/file") str(custom_pathlike) # "CustomPathlike(path='folder/file')" - fails in "git add CustomPathlike(path='folder/file')"os.fspath(custom_pathlike) # "folder/file" - works in "git add folder/file"I realise that that was unclear in both the PR and the original issue (so I've added this example to the original issue). |
Byron commented Dec 2, 2025
Thanks a lot, this definitely helped me understand that these changes aren't meant to address that one thing I thought they do 😅. My feeling is that the added tests don't actually fail on master, and thus should be removed. But if they do, please feel free to put them into a separate PR so I see them failing. |
George-Ogden commented Dec 2, 2025
See #2088 for failing tests |
Byron commented Dec 2, 2025
Thanks for giving it a shot. Admittedly, @2088 is surprisingly complex and fails in more places than just the two I thought it would fail in. To my mind, a cherry-pick of 1710626 onto Do you want to try again, or remove the added tests here in absence of a demonstration of failure? |
George-Ogden commented Dec 2, 2025
I've done that in #2089 |
Byron commented Dec 4, 2025
Thanks a lot for your patience, just one more thing: 1710626 adds tests which I believe should have shown that they won't work on If you don't feel like this has a chance to be fixed, then I think these tests can be removed by force-pushing without this commit for this PR to be merged. Otherwise, there can be a PR on Thank you, and… we will get there :). |
George-Ogden commented Dec 4, 2025
However, both Lines 86 to 98 in 1710626
and Lines 985 to 994 in 0fcf291
Ran on main successfully (and were included before this PR)The difference in Lines 1216 to 1222 in 1710626
which fails on main is that the path is wrapped in a PathLikeMock, which has an interface similar to the one described above:Lines 55 to 60 in 1710626
|
Byron commented Dec 5, 2025
I see, thanks for clarifying and digging out the non-unicode tests on Then I even more so think that the tests in 1710626 as duplicates of the tests above serve no purpose. The |
This reverts commit 1710626.
George-Ogden commented Dec 5, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
All reverted! I agree that the tests don't add much. |
Byron commented Dec 6, 2025
Alright, let's do this! |
eecc28d into gitpython-developers:mainUh oh!
There was an error while loading. Please reload this page.
George-Ogden commented Dec 6, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Thanks, that's great 🥳. Can you release a new version please? |
Byron commented Dec 7, 2025
I will do this at the end of the year, time for more fixes and features to be collected. |
Fixes#2085
Replaces instances of
str(path)withpath.__fspath__()for more general usage.I also moved the clone tests into a separate file that existed before but only contained a single test.