[New-bugs-announce] [issue39291] "pathlib.Path.link_to()" and "pathlib.Path.symlink_to()" have reversed usage
Rockmizu
report at bugs.python.org
Fri Jan 10 12:50:14 EST 2020
New submission from Rockmizu <Rockmizu at gmail.com>:
Python version: Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32
The usage of symlink_to() is link.symlink_to(target)
while the usage of link_to() is target.link_to(link).
This could be confusing.
Here is an example:
>>> import pathlib
>>> target = pathlib.Path('target.txt')
>>> p1 = pathlib.Path('symlink.txt')
>>> p2 = pathlib.Path('hardlink.txt')
>>> p1.symlink_to(target)
>>> p2.link_to(target) # expected usage
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\Program Files\Python38\lib\pathlib.py", line 1346, in link_to
self._accessor.link_to(self, target)
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'hardlink.txt' -> 'target.txt'
>>> target.link_to(p2) # current usage
>>>
Since os.symlink() and os.link() have the same argument order,
>>> import os
>>> os.symlink('target.txt', 'symlink.txt')
>>> os.link('target.txt', 'hardlink.txt')
>>>
it would be nicer if the pathlib has the same argument order too.
----------
components: Library (Lib)
messages: 359745
nosy: Rockmizu
priority: normal
severity: normal
status: open
title: "pathlib.Path.link_to()" and "pathlib.Path.symlink_to()" have reversed usage
type: behavior
versions: Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39291>
_______________________________________
More information about the New-bugs-announce
mailing list