Currently it is decided if to use the srcentry in the copy_function by checking if the copy_function is copy() or copy2(). This will fail if the copy_function is a modified copy() or copy2() function. To control if the copy_function gets a srcentry or srcname parameter, added the use_srcentry parameter.
It turns out that's a bug I introduced in PR-7874. I'm providing: https://github.com/python/cpython/pull/11997 ...which fixes it without introducing a new parameter. I also verified that monkey patching shutil.copy2 and shutil.copy doesn't cause any issue.
You are right about the bug. The funny thing is, I never saw it. The problem I see is another. The use_srcentry variable in the _copytree function is set by determining if the copy_function is the function copy2 or copy. If so the srcentry is passed to the copy_function. If the user passes a custom copy_function to copytree, this function will ever become only the srcname and not the srcentry. To summarize it: The integrated copy_functions get the srcentry and custom copy_functions get the srcname. But what is if the custom copy_function is a edited copy2 function or needs the srcentry? In order to fix this was my idea to have a parameter to control if the custom copy_function get the srcentry or a srcname. Please write me if there is anything misconception in my thoughts or other objections?
When user uses copy_function argument, the callback function should always receive path strings, both for consistency and for not breaking backward compatibility. This line: use_srcentry = copy_function is copy2 or copy_function is copy ...makes sure of that (only passes DirEntry instances around if copy_function is not specified by user).
Okay, than this behaviour is wanted. I only thought that the user should have more control about it, but you are right, only the path string is better to handle. I will close the PR.
History
Date
User
Action
Args
2022-04-11 14:59:09
admin
set
github: 79829
2019-02-24 17:46:05
xxxxxxx
set
status: open -> closedresolution: not a bugmessages: + pull_requests: + <pull%5Frequest12051>