os.scandir(): add option to yield the given path itself
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Feature or enhancement
I think it would be nice if os.scandir() had an option (that defaults to the current behaviour) which makes it also yield the root path itself as given by its path argument.
The benefit would be, that if one has code like e.g.:
def scandirtree(path):
for p in os.scandir(path):
if p.is_dir(follow_symlinks=False):
yield p
yield from scandirtree(p)
else:
yield p
one would also yield path and process that as well (in whatever one does with the generator).
It doesn't seem to be possible right now to write a warpper around scandir which would just yield path first, since one cannot create os.DirEntry objects (see #71983).
Pitch
The above in turn would be the familiar behaviour of many tools, e.g.
$ rm -rf path
also removes the path itself, not just its contents.
find path
also finds path itself.
Etc. pp.
So anyone who wants to implement a tool like these or similar behaviour, would no longer need to specially handle the path itself.
Previous discussion
https://discuss.python.org/t/os-scandir-should-have-an-option-to-also-yield-the-path-itself/18383
Thanks,
Chris.
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 os.scandir() 入口點開始,檢視 issue #71983 及其連結討論中所討論的相關限制。定義一種 opt-in 行為,在保留目前預設行為的同時,將給定路徑本身作為相容結果傳回,然後加入 coverage 以展示這兩種行為。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- operating-systems
- Issue 類型
- 功能
- 難度
- 5/5
- 預估耗時
- 一週以上
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 32/100