Message310983
Thanks for the bug report!
shutil.move should certainly accept a path object, as shutil.copy does, though it should be noted that in your example, 'path' could become out of date as it does not refresh the path information. For example, with shutil.move fixed:
>>> import os, pathlib, shutil
>>> os.mkdir('test1')
>>>
>>> os.mkdir('test2')
>>> path = pathlib.Path('test1')
>>> path.absolute()
PosixPath('/Users/e/Development/OSS/cpython/test1')
>>> shutil.move(path, 'test2')
'test2/test1'
>>> path.absolute()
PosixPath('/Users/e/Development/OSS/cpython/test2')
test1 is now actually at '/Users/e/Development/OSS/cpython/test2/test1'
For the fix:
I did a bit of digging and the error comes from a helper method _basename that uses rstrip to remove a trailing separator, hence the error as rstrip doesn't exist for a path object (and I don't think it makes sense that it should, though that was one solution). Removing the trailing separator is, however, very important in determining the full destination path.
After trying a few different approaches, I think the simplest way is to cast the src to a string before finding its appropriate basename. I also added some comments to make it more clear why _basename is used over os.path.basename to hopefully save someone else time in the future.
A more robust option would be to explicitly handle Path objects or to handle exceptions for any dst that cannot be cast to a string. However, the current patch fixes the issue without introducing new problems. |
|
Date |
User |
Action |
Args |
2018-01-28 19:13:57 | emilyemorehouse | set | recipients:
+ emilyemorehouse, craigh |
2018-01-28 19:13:57 | emilyemorehouse | set | messageid: <1517166837.39.0.467229070634.issue32689@psf.upfronthosting.co.za> |
2018-01-28 19:13:57 | emilyemorehouse | link | issue32689 messages |
2018-01-28 19:13:57 | emilyemorehouse | create | |
|