python / python/cpython

`os.removedirs()` should define whether it follows symlinks

未关闭
#134,161 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

3.13 3.14 3.15 docs
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

Documentation

Many functions in os do not properly specify whether or not they follow symlinks. The Files and Directories even slightly implies that the default is more to follow symlinks (and only with follow_symlinks=False not).

For some functions (like os.rmdir() one might argue this is not important because they're the counterparts of well-known POSIX/C functions and for them it's well-defined.

But e.g. os.removedirs() seem to have no such counterpart and since the documentation doesn't mention anything, the current behaviour (which AFAICS is not following symlinks) might just be some implementation detail.

For os.removedirs() there are even two interesting cases in e.g. os.removedirs("a/b/c/d"):

  • if d (i.e. the final pathname component) is a symlink to a directory the referred directory is not removed (at least not in the current code, which uses os.rmdir() on the pathname)
  • if e.g. b is a symlink to a directory, which contains only c/d, then b is followed when rmdiring a/b/c/d and a/b/c but is not followed when rmdiring a/b (and the target of b isn’t removed).

All this kinda follows the spirit of POSIX' pathname resolution, but still it would IMO be nice to have it clearly defined.

Cheers,
Chris.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 Python 文档的“Files and Directories”部分以及 os.removedirs() 和 os.rmdir() 的条目开始。记录 os.removedirs() 是否会在路径的最终组件和中间组件中跟随符号链接,从而使 issue 中描述的行为明确,并与文档所述语义保持一致。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
documentation
Issue 类型
文档
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
40/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。