Skip to content
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

"pathlib.Path.link_to()" and "pathlib.Path.symlink_to()" have reversed usage #83472

Closed
Rockmizu mannequin opened this issue Jan 10, 2020 · 6 comments
Closed

"pathlib.Path.link_to()" and "pathlib.Path.symlink_to()" have reversed usage #83472

Rockmizu mannequin opened this issue Jan 10, 2020 · 6 comments
Labels
3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@Rockmizu
Copy link
Mannequin

Rockmizu mannequin commented Jan 10, 2020

BPO 39291
Nosy @pitrou, @nanjekyejoannah, @Rockmizu, @barneygale

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:

assignee = None
closed_at = <Date 2020-01-10.18:37:27.997>
created_at = <Date 2020-01-10.17:50:14.125>
labels = ['3.8', 'type-bug', 'library']
title = '"pathlib.Path.link_to()" and "pathlib.Path.symlink_to()" have reversed usage'
updated_at = <Date 2021-01-19.09:33:11.404>
user = 'https://github.com/Rockmizu'

bugs.python.org fields:

activity = <Date 2021-01-19.09:33:11.404>
actor = 'yota moteuchi'
assignee = 'none'
closed = True
closed_date = <Date 2020-01-10.18:37:27.997>
closer = 'pitrou'
components = ['Library (Lib)']
creation = <Date 2020-01-10.17:50:14.125>
creator = 'Rockmizu'
dependencies = []
files = []
hgrepos = []
issue_num = 39291
keywords = []
message_count = 6.0
messages = ['359745', '359747', '359748', '364057', '364058', '385249']
nosy_count = 5.0
nosy_names = ['pitrou', 'yota moteuchi', 'nanjekyejoannah', 'Rockmizu', 'barneygale']
pr_nums = []
priority = 'normal'
resolution = 'wont fix'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue39291'
versions = ['Python 3.8']

@Rockmizu
Copy link
Mannequin Author

Rockmizu mannequin commented Jan 10, 2020

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.

@Rockmizu Rockmizu mannequin added 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jan 10, 2020
@pitrou
Copy link
Member

pitrou commented Jan 10, 2020

Ahah. Nice catch!

Well, it's a pity this got overlooked when we added Path.link_to(). But I'm afraid it's late to change it now, since this has been released, and changing the argument order would break existing code in potentially dangerous ways.

Note the original issue where this was added was bpo-26978.

@pitrou
Copy link
Member

pitrou commented Jan 10, 2020

Closing as won't fix. If you feel strongly about this, I would suggest to bring the discussion on python-dev: https://mail.python.org/mailman3/lists/python-dev.python.org/

@pitrou pitrou closed this as completed Jan 10, 2020
@pitrou pitrou closed this as completed Jan 10, 2020
@barneygale
Copy link
Mannequin

barneygale mannequin commented Mar 12, 2020

Per discussion on the mailing list, I'd like to request that this bug be re-opened.

https://mail.python.org/archives/list/python-dev@python.org/thread/7QPLYW36ZK6QTW4SV4FI6C343KYWCPAT/

@nanjekyejoannah
Copy link
Member

Am hesitant on re-opening this.

I think it sounds more meaningful to open a new issue for the new
suggestion that requires deprecating this
current behavior and introducing the new intended functionality.

Best,
Joannah

On Thu, Mar 12, 2020 at 8:40 PM Barney Gale <report@bugs.python.org> wrote:

Barney Gale <barney.gale@gmail.com> added the comment:

Per discussion on the mailing list, I'd like to request that this bug be
re-opened.

https://mail.python.org/archives/list/python-dev@python.org/thread/7QPLYW36ZK6QTW4SV4FI6C343KYWCPAT/

----------
nosy: +barneygale


Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue39291\>


--
Best,
Joannah Nanjekye

*"You think you know when you learn, are more sure when you can write, even
more when you can teach, but certain when you can program." Alan J. Perlis*

@yotamoteuchi
Copy link
Mannequin

yotamoteuchi mannequin commented Jan 19, 2021

one option to could be to create a hardlink_to() method which is link.hardlink_to(target) and in a few release, deprecate link_to ? :)

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants