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 iter_change_type diff renamed property to prevent warning#1918

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

Merged
Byron merged 2 commits intogitpython-developers:mainfromkamilkrzyskow:patch-1
Jun 8, 2024

Conversation

kamilkrzyskow
Copy link
Contributor

@kamilkrzyskowkamilkrzyskow commentedMay 28, 2024
edited
Loading

Hello 👋,
in#1886 ande7dec7d a proper warning message was introduced for the usage ofDiff.renamed pointing to useDiff.renamed_file.
However, the usage of this property wasn't changed in theiter_change_type (since 3 years at that), so the internals use deprecated code 😞

GitPython/git/diff.py

Lines 328 to 329 in9fbfb71

elifchange_type=="R"anddiffidx.renamed:
yielddiffidx

Given that the code wasn't reported yet, perhaps I'm doing something wrong using theiter_change_type and there are better ways 👀 I'm using a custom MkDocs hook to run GitPython and check for renames to automatically create redirects mappings for paths, and another plugin handles the redirect creation for the static pages.
Here is the line which triggered the warning

And the CI:

Warning

As this is a one line change, I took the liberty to omit setting up an environment and just used the GitHub GUI to make a small change.
I also didn't investigate deeper to check if theiter_change_type has any tests.

Thanks for your time ✌️

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 for investigating this issue!

Unfortunately, no existing test fails, showing wrong expectations, which means that it's entirely unclear what this change does. Since the diff-code is confusing enough as it is, any change must be accompanied by a test that protects it from regression and makes clear what the purpose of the change is.

Of course I understand that producing a test that fails without this change, ideally pushed in a commit before this one, is additional work, and it's understandable this request might go beyond what you can provide. If so, please feel free to close this PR, but otherwise, please do take your time, it's appreciated.

@kamilkrzyskow
Copy link
ContributorAuthor

kamilkrzyskow commentedMay 28, 2024
edited
Loading

OK, I expected this turn of events 😅, I'll see what I can do over the week.

EDIT:
I see that you allow for testing many things in one test function:

deftest_diff_with_rename(self):
output=StringProcessAdapter(fixture("diff_rename"))
diffs=Diff._index_from_patch_format(self.rorepo,output)
self._assert_diff_format(diffs)
self.assertEqual(1,len(diffs))
diff=diffs[0]
self.assertTrue(diff.renamed_file)
self.assertTrue(diff.renamed)
self.assertEqual(diff.rename_from,"Jérôme")
self.assertEqual(diff.rename_to,"müller")
self.assertEqual(diff.raw_rename_from,b"J\xc3\xa9r\xc3\xb4me")
self.assertEqual(diff.raw_rename_to,b"m\xc3\xbcller")
assertisinstance(str(diff),str)
output=StringProcessAdapter(to_raw(fixture("diff_rename_raw")))
diffs=Diff._index_from_raw_format(self.rorepo,output)
self.assertEqual(len(diffs),1)
diff=diffs[0]
self.assertIsNotNone(diff.renamed_file)
self.assertIsNotNone(diff.renamed)
self.assertEqual(diff.rename_from,"this")
self.assertEqual(diff.rename_to,"that")
self.assertEqual(diff.change_type,"R")
self.assertEqual(diff.score,100)
self.assertEqual(len(list(diffs.iter_change_type("R"))),1)

I'll hijack this loose rule and just add a test for lack of warnings when running theiter_change_type inside those functions 👌

EDIT2:

Or in this filehttps://github.com/gitpython-developers/GitPython/blob/main/test/deprecation/test_basic.py 👌

@Byron
Copy link
Member

Thanks a lot, and please do!

And maybe after doing that, putting matters into their own test won't be hard anymore, but if not, also no problem at all.

@kamilkrzyskow
Copy link
ContributorAuthor

There you go, I added the test to the other deprecation tests intest_basic
I hope this will get released soon ;]

@kamilkrzyskowkamilkrzyskow requested a review fromByronJune 8, 2024 00:36
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.

My apologies, I realize my mistake now!rename is deprecated and was used internally, even thoughrenamed_file should be used.
I thought this change is a affecting the logic of the diff, even though it's not doing that at all.
🤦‍♂️

Oh well, thanks again for bearing with me here.

kamilkrzyskow reacted with hooray emojikamilkrzyskow reacted with rocket emoji

def test_diff_iter_change_type(diffs: "DiffIndex") -> None:
"""The internal DiffIndex.iter_change_type function issues no deprecation warning."""
with assert_no_deprecation_warning():
Copy link
Member

Choose a reason for hiding this comment

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

There must have been a misunderstanding. It's not about deprecation warnings, it's about adding a test that fails without the change presented here, while making clear what the issue truly is.

@ByronByron merged commitee987da intogitpython-developers:mainJun 8, 2024
26 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ByronByronByron approved these changes

Assignees
No one assigned
Labels
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@kamilkrzyskow@Byron

[8]ページ先頭

©2009-2025 Movatter.jp