`如何启用制表符或空格缩进的错误?

2024-10-02 02:40:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图实施一些简单的python格式规则。我找到了pylint,我很高兴。然而,我需要执行的一个更简单的格式检查是:仅制表符或仅空格缩进。

pylint中,如何启用制表符或空格缩进的错误或警告?

我看到pylint有{a1}。但是w0311不只强制制表符或空格。。。它仍然支持制表符或空格。

我需要我所有的python文件都是一种缩进类型。

(二)

另外,如果您想知道我是如何使用pylint来执行我的规则的。我有一个运行pylint的shell脚本,我使用set -o errexit,这与构建挂钩。因此,如果pylint发现了某个非零值的东西,它就会退出并导致构建失败。


Tags: 文件脚本警告类型规则a1格式错误
1条回答
网友
1楼 · 发布于 2024-10-02 02:40:59

你要找的可能是:

mixed-indentation (W0312): Found indentation with %ss instead of %ss Used when there are some mixed tabs and spaces in a module.

在以下情况下引发:

Description

Used when there are some mixed tabs and spaces in a module.

Explanation

Python interprets tabs and spaces differently, so consistent indentation is critical to the correct interpretation of blocks in Python syntax.

This warning is raised when a mix of both spaces and tabs is used in indentation—or more precisely, when an indent is detected that is not consistent with the indent-string option. By default, indent-string is set to four spaces, the style of indentation recommended in PEP 8.

编辑1:

据我所知(目前为止),Pylint没有一个选项来“强制”您的编码风格中的制表符/空格。上面提到的W0312用于警告代码中的缩进不一致。在

我用一个技巧来强制缩进:在PyCharm上打开你的项目(在社区版也是免费的)如果IDE检测到不一致,它会警告你,它会给你一个选项来更改当前文件的缩进,或者保持它的原样!在

相关问题 更多 >

    热门问题