Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upbpo-39390: fix argument types for ignore callback of shutil.copytree #18122
Conversation
@@ -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, |
This comment has been minimized.
This comment has been minimized.
giampaolo
Jan 22, 2020
•
Contributor
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).
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bedevere-bot
commented
Jan 22, 2020
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
finally: | ||
shutil.rmtree(dst_dir) | ||
finally: | ||
shutil.rmtree(src_dir) |
This comment has been minimized.
This comment has been minimized.
giampaolo
Jan 22, 2020
Contributor
You can use self.addCleanup(shutil.rmtree, path)
and avoid the try/finally blocks.
This comment has been minimized.
This comment has been minimized.
mbarkhau
Jan 22, 2020
Author
Contributor
Hmm, actually from the looks of it, that's already part of self.mkdtemp
.
This comment has been minimized.
This comment has been minimized.
95953fd
to
b0c0108
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 [] |
This comment has been minimized.
This comment has been minimized.
giampaolo
Jan 23, 2020
Contributor
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
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
mbarkhau
Jan 23, 2020
Author
Contributor
Since it's called recursively, it's actually called a total of 9 times, but in any case it works.
b0c0108
to
eebcd7a
This comment has been minimized.
This comment has been minimized.
miss-islington
commented
Jan 24, 2020
Thanks @mbarkhau for the PR, and @giampaolo for merging it |
This comment has been minimized.
This comment has been minimized.
miss-islington
commented
Jan 24, 2020
I'm having trouble backporting to |
This comment has been minimized.
This comment has been minimized.
Could you backport this to 3.8? |
This comment has been minimized.
This comment has been minimized.
I'll have a look. |
…nGH-18122). (cherry picked from commit 8870433) Co-authored-by: mbarkhau <mbarkhau@gmail.com>
This comment has been minimized.
This comment has been minimized.
bedevere-bot
commented
Jan 24, 2020
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 <mbarkhau@gmail.com>
…nGH-18122). (cherry picked from commit 8870433) Co-authored-by: mbarkhau <mbarkhau@gmail.com>
mbarkhau commentedJan 22, 2020
•
edited by bedevere-bot
The directory being copied.
An ignore function for debugging.
Python 3.7
Python 3.8
https://bugs.python.org/issue39390