跳到内容

path-constructor-current-directory (PTH201) (路径构造器当前目录)

派生自 flake8-use-pathlib linter。

修复总是可用的。

作用

检查使用当前目录初始化的 pathlib.Path 对象。

为什么这不好?

Path() 构造函数默认为当前目录,因此显式传递(如 ".")是不必要的。

示例

from pathlib import Path

_ = Path(".")

建议改为

from pathlib import Path

_ = Path()

修复安全性

如果括号内有注释,此修复被标记为不安全,因为应用修复将会删除它们。

参考