You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using pathlib with shutil usually works, but there are some quirks when it comes to return types. As an example, see the copy function (but other functions are affected as well):
In this case, if a Path object gets passed in as dst, it will be returned unchanged if it is not a directory, but a str will be returned if it is a directory. That's unexpected, the return type should be consistent, probably by always returning a str.
I assume that pathlib support is mostly incidental in shutil, considering that the latter predates the former. shutil should probably be reviewed for proper pathlib support at some point. (See also a few other pathlib/shutil related issues reported here.)
Fixes issue python#132322 by normalizing return types in shutil.copy, copy2, copyfile, copytree, and move using os.fspath(), so that they consistently return str even when pathlib.Path is passed.
All relevant tests pass locally
Bug report
Bug description:
Using
pathlib
withshutil
usually works, but there are some quirks when it comes to return types. As an example, see thecopy
function (but other functions are affected as well):cpython/Lib/shutil.py
Lines 468 to 484 in 67ded6a
In this case, if a
Path
object gets passed in asdst
, it will be returned unchanged if it is not a directory, but astr
will be returned if it is a directory. That's unexpected, the return type should be consistent, probably by always returning astr
.I assume that pathlib support is mostly incidental in shutil, considering that the latter predates the former. shutil should probably be reviewed for proper pathlib support at some point. (See also a few other pathlib/shutil related issues reported here.)
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
The text was updated successfully, but these errors were encountered: