跳到内容

re-sub-positional-args (B034)

源自 flake8-bugbear linter。

作用

检查对 re.subre.subnre.split 的调用,这些调用将 countmaxsplitflags 作为位置参数传递。

为什么这不好?

countmaxsplitflags 作为位置参数传递给 re.subre.subnre.split 可能会导致混淆,因为 re 模块中的大多数方法都接受 flags 作为第三个位置参数,而 re.subre.subnre.split 具有不同的签名。

相反,请将 countmaxsplitflags 作为关键字参数传递。

示例

import re

re.split("pattern", "replacement", 1)

建议改为

import re

re.split("pattern", "replacement", maxsplit=1)

参考