-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
shutil.copytree - 3.8 changed argument types of the ignore callback #83571
Comments
In Python 3.8, the types of the parameters to the ignore callable appear to have changed. Previously the I would suggest adding the following to the documentation https://github.com/python/cpython/blob/master/Doc/library/shutil.rst .. versionchanged:: 3.8 |
This looks like a backward incompatible change in 3.8. Should not copytree convert arguments of the ignore callback to str and list correspondingly? |
Indeed.
Well, since any existing code probably expects that behavior (or at least probably works if that is the case), I would be for such a change. I'm not sure what your policy is though. If there is recently written code that assumes the new types, are you OK with that breaking if it is changed back? I guess since it's an undocumented breaking change, it shouldn't be too much of an issue. |
Is there anything I can do to help move this forward? |
It should. I think it makes sense to just do this for Python 3.8.2 instead of updating the doc. |
Unless somebody else wants to, I could have a go at an PR to update shutil.py |
Yes, thanks. Whoever got bit by this is either getting an exception or not the intended behavior (due to failed string comparison). I doubt anybody is relying on the new type checking since it's not documented. If they are, they are probably just doing: def callback(name, names):
if not isinstance(name, str): # bugfix 3.8
name = name.name
... |
For completeness, a similar problem is present also on python < 3.8 if passing a pathlib.Path type as *src*: the callback function will receive a pathlib.Path type once, and then string types. |
Fair point. I'll have a look. |
I do not think this is a problem. If you pass a string, you will get a string, so existing code will continue to work as before. The only problem if you pass a string, but get an unexpected type. |
I don't think we need to change anything on < 3.8, but 3.8 and 3.9 will always convert *src* to str via os.fspath(), which IMO is more consistent (e.g. os.path.* functions and others do the same). |
Somebody might have code that is running against a flat directory and have written their ignore function expecting to get a pathlib.Path, because that's the only case they encountered. This change would break their code and so would an upgrade to 3.9 with the patch that was just merged. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: