Skip to content

Document behavior of Path.symlink_to() when source already exists #132416

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

Open
bmispelon opened this issue Apr 11, 2025 · 0 comments
Open

Document behavior of Path.symlink_to() when source already exists #132416

bmispelon opened this issue Apr 11, 2025 · 0 comments
Labels
docs Documentation in the Doc dir topic-pathlib

Comments

@bmispelon
Copy link
Contributor

bmispelon commented Apr 11, 2025

Documentation

The documentation for Path.symlink_to() [1] does not mention what happens when the source already exists, e.g.:

>>> from pathlib import Path
>>> Path("source").symlink_to("target1")
>>> Path("source").symlink_to("target2")
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    Path("source").symlink_to("target2")
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "/usr/lib/python3.13/pathlib/_local.py", line 789, in symlink_to
    os.symlink(target, self, target_is_directory)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileExistsError: [Errno 17] File exists: 'target2' -> 'source'

(The same applies to os.symlink [2] by the way)

Linked PRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir topic-pathlib
Projects
Status: Todo
Development

No branches or pull requests

2 participants