python / python/cpython

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

未關閉
#132,416 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

docs topic-pathlib
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

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
  • gh-132704
  • gh-132810

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

先查看 issue 中連結的 pathlib.Path.symlink_to() 文件,然後對照 os.symlink() 文件了解相同的行為。完成的標準是兩個條目都說明目的地路徑已存在時會發生什麼,包括此處所示的 FileExistsError 範例。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
documentation
Issue 類型
文件
難度
2/5
預估耗時
1-3 小時
活躍度
停滯
描述清晰度
描述清楚
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。