-
-
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
base: main
Are you sure you want to change the base?
Respect os.Pathlike
#2086
Conversation
36bd3ba to
5d26325
Compare
|
Also, I notice you skip mypy because it produces errors. Why not pin the version and increment it periodically? |
|
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 :). |
|
It seems that I won't get my copilot review here, so I wonder why you'd not be calling |
|
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 | ||
| if not isinstance(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.
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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
db456d7 to
57a3af1
Compare
|
I've added a few tests, but lots of the calls work on internal APIs, so they won't make much difference. In these cases, calling |
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.
b45854a to
15f985b
Compare
15f985b to
8434967
Compare
|
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. |
|
Sorry, I meant to add this comment with the changes I made yesterday: For example, the |
|
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 |
|
I've added some non-ASCII characters into the tests. However, the main point of the pull request is with objects that follow the import os
from dataclasses import dataclass
@dataclass
class CustomPathlike:
path: str
def __fspath__(self) -> str:
return self.path
custom_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). |
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.