-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-39390: fix argument types for ignore callback of shutil.copytree #18122
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
Conversation
Lib/shutil.py
Outdated
@@ -478,12 +478,12 @@ def _copytree(entries, src, dst, symlinks, ignore, copy_function, | |||
continue | |||
# otherwise let the copy occur. copy2 will raise an error | |||
if srcentry.is_dir(): | |||
copytree(srcobj, dstname, symlinks, ignore, | |||
copytree(srcname, dstname, symlinks, ignore, |
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 removes the speedup originally introduced. I think you can just do this:
ignored_names = ignore(os.fspath(src), [x.path for x in entries])
There should be a unit test which makes sure the callback function receives a string regardless of the type passed as input (str, pathlib.Path, os.DirEntry).
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.
I have made the requested changes; please review again.
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.
Sorry, I missed something for the test.
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.
Ok, I think it should be good now.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
f18cf4f
to
95953fd
Compare
Lib/test/test_shutil.py
Outdated
finally: | ||
shutil.rmtree(dst_dir) | ||
finally: | ||
shutil.rmtree(src_dir) |
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.
You can use self.addCleanup(shutil.rmtree, path)
and avoid the try/finally blocks.
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.
Hmm, actually from the looks of it, that's already part of self.mkdtemp
.
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.
I think the test should be ok now.
95953fd
to
b0c0108
Compare
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.
I added one last nitpick. Also, please add a NEWS entry with blurb.
self.assertEqual(len(names), len(set(names))) | ||
for name in names: | ||
self.assertIsInstance(name, str) | ||
return [] |
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.
I'd add a check to make sure this function is called 3 times. Something like:
def test_copytree_arg_types_of_ignore(self):
def _ignore(src, names):
...
flags.append(None)
flags = []
... # body
self.assertEqual(len(flags), 3) # last line
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.
Fair point.
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.
Since it's called recursively, it's actually called a total of 9 times, but in any case it works.
b0c0108
to
eebcd7a
Compare
Thanks @mbarkhau for the PR, and @giampaolo for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8. |
I'm having trouble backporting to |
Could you backport this to 3.8? |
I'll have a look. |
GH-18168 is a backport of this pull request to the 3.8 branch. |
…nGH-18122). (cherry picked from commit 8870433) Co-authored-by: mbarkhau <[email protected]>
The directory being copied.
An ignore function for debugging.
Python 3.7
Python 3.8
https://bugs.python.org/issue39390