当目录是另一个目录的前缀时,Pylint 递归错误

问题描述 投票:0回答:1

当我的目录名称是另一个目录的前缀时,我观察到 pylint 的奇怪行为。这是重现的最小设置:

mkdir pylint_test
cd pylint_test
mkdir dataset
touch dataset/__init__.py
mkdir dataset_123
echo "from collections import Counter" > dataset_123/a.py
echo "[master]\nenable= all" > pylintrc
pylint --recursive=y .

我希望在 a.py 中未使用导入时收到错误,但这不会发生。更奇怪的是 - 如果我删除数据集中的文件

__init__.py
(或重命名它),我会得到预期的输出:

pylint --recursive=y .
************* Module a
eval_123/a.py:1:0: C0114: Missing module docstring (missing-module-docstring)
eval_123/a.py:1:0: W0611: Unused Counter imported from collections (unused-import)

更奇怪的是 - 如果我不删除

__init__.py
而是将两个目录分别重命名为
eval
eval_123
一切都会正常。

另一个实验是将 dataset_123 重命名为 dataset_b123。在这种情况下,pylint 会按预期报告问题(即使存在

__init__.py

我使用的是 Mac Ventura 13.4.1,以下是我的软件包版本:

pylint --version
pylint 2.15.2
astroid 2.13.5
Python 3.8.13 (default, Oct 19 2022, 17:52:09)
[Clang 12.0.0 ]

然而,这也可以在其他 python 版本中重现。

有人知道这是怎么回事吗?

python pylint
1个回答
0
投票

这似乎是一个错误,我建议在 pylint GitHub 存储库上提出问题。

我能够将问题缩小到这行,这是在

_discover_files
方法下。该方法负责递归地发现Python模块和包(相当于
--recursive=y
选项)。

if any(root.startswith(s) for s in skip_subtrees):
     # Skip subtree of already discovered package.
     continue

我相信如果搜索确定我们已经在包中,此检查的目的是排除子树。然而,它也无意中排除了以相同名称开头的其他存储库。

© www.soinside.com 2019 - 2024. All rights reserved.