astral-sh/ruff

`PTH*`: Incorrect suggestion to use `Pathlib` when using file descriptors

Open

#17,699 创建于 2025年4月29日

在 GitHub 查看
 (7 评论) (0 反应) (0 负责人)Rust (2,088 fork)batch import
bugfixeshelp wantedrule

仓库指标

Star
 (47,527 star)
PR 合并指标
 (平均合并 3天 8小时) (30 天内合并 573 个 PR)

描述

Multiple pathlib rules recommend the use of pathlib.Path over their os equivalent even when they're used with a bytes string or directory descriptor which aren't supported by pathlib.

One such example is

import os
os.listdir(1)
$ ruff --version
ruff 0.11.7
$ ruff check --isolated --select PTH208 t.py
t.py:2:1: PTH208 Use `pathlib.Path.iterdir()` instead.
  |
1 | import os
2 | os.listdir(1)
  | ^^^^^^^^^^ PTH208
  |

Found 1 error.

Past instances of the same or similar error:

贡献者指南