Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix blob filter types#1459

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

AustinScola
Copy link
Contributor

Fix the types and type annotations of some of the blob filter code.

Fix the types and type annotations of some of the blob filter code.
Copy link
Member

@ByronByron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks a lot, the change will be appreciated!

There is some usage ofstr(…) conversions which requires attention, but with that fix there should be nothing in the way of merging.

def __call__(self, stage_blob: Blob) -> bool:
path =stage_blob[1].path
def __call__(self, stage_blob:Tuple[StageType,Blob]) -> bool:
path: str = str(stage_blob[1].path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Paths can't be converted tostr as this implies an interpreter defined encoding.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can you explain what you mean by this or give an example?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Before the change it looked like this:

path = stage_blob[1].path

And after the change it should still be looking like this but possibly with type annotations added to please the type checker. Creating new strings withstr(…) changes the way the program functions, and does so in a breaking way due to encodings being unspecified for paths on linux.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Changed to use paths instead of strs. Still not really sure what you mean by encodings being unspecified for paths on linux.

for p in self.paths:
if path.startswith(p):
if path.startswith(str(p)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

There has to be a way to do this withoutstr(…), please see above for the reason.

Remove usage of `PosixPath.is_relative_to` because it was added inPython 3.9 and earlier versions of Python are supported by `GitPython`.
Copy link
Member

@ByronByron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks a lot for the changes and the continued effort! I think usingPathshould be correct in terms of required encodings, at least it's as good as it gets.

I also understand that just converting to a known type temporarily is probably the easiest than having to try to support all possible input types, so let's go with that even though it seemspotentially wasteful.

There is one more issue I seem to be seeing, and am looking forward to hearing your opinion.

for pathlike in self.paths:
path: Path = pathlike if isinstance(pathlike, Path) else Path(pathlike)
# TODO: Change to use `PosixPath.is_relative_to` once Python 3.8 is no longer supported.
if all(i == j for i, j in zip(path.parts, blob_path.parts)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is this not another way of writingpath1 == path2, since all path components (here.parts) have to be equivalent? The benefit of doing so of course is that it ignores which path separator is used, but I am having trouble to understand how this checks thatblob_path starts with one ofself.paths.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think this should work becausezip stops when the shortest of the arguments is exhausted. So it is only checking ifall the path components are equivalent in the case that the length of theparts are equal. But, when one path has more parts than the other, then it is checking that the longer path starts with the shorter path.

Example:

defstartswith(a,b):returnall(i==jfori,jinzip(a,b))a= [1,2,3]b= [1,2]assertstartswith(a,b)

Copy link
ContributorAuthor

@AustinScolaAustinScolaJun 27, 2022
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Alternatively, the implementation ofPosixPath.is_relative_to looks like this:

defis_relative_to(self,*other):"""Return True if the path is relative to another path or False.        """try:self.relative_to(*other)returnTrueexceptValueError:returnFalse

We could do something similar to this in-place.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks for the explanation, I see how this works now and why this is correct. The alternative has to remain a TODO until it becomes available, and looking at the code I am happy to suggest to not ever go there - the try:except clause seems like a deal-breaker to me. It's entirely up to you though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Actually, let me undo what I last said. I once again think this implementation is incorrect, as these paths are not equivalent.

base= [1,2,3]added_path= [1,2]

The above would match even thoughadded_path is not contained in base.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Good catch, I pushed a change that addresses this and adds a test too.

Copy link
Member

@ByronByron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks a lot for the test and the fix. It's definitely an under-tested area of GitPython as the issue wasn't detected by any test prior.

I left a comment, but when clarified, this PR is ready to be merged.

@Byron
Copy link
Member

Byron commentedJul 2, 2022
edited
Loading

Thanks a lot for your contribution and going through the review process with me! I hope the code is more robust now, also knowing that the current implementation (independently of your contribution) generally lacks beyond repair compared to what git actually does.

AustinScola reacted with thumbs up emoji

@ByronByron merged commitca2cf10 intogitpython-developers:mainJul 2, 2022
@ByronByron added this to thev3.1.28 - Bugfixes milestoneJul 2, 2022
@AustinScolaAustinScola deleted the ascola/fix-blob-filter-types branchJuly 2, 2022 12:56
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ByronByronByron requested changes

Assignees
No one assigned
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
@AustinScola@Byron

[8]ページ先頭

©2009-2025 Movatter.jp