A bracket set in a pattern names the same character twice

tx0/python:regex-duplicate-class-memberrecommendedwarningbug

What it finds

[a-z_a] lists a twice, once in the range and once on its own. The class matches the same either way, so the repetition is harmless in itself, but it often shows that a different character was meant, or that an unescaped - made a range where none was intended.

From the rule's source, regex_duplicate_class_member.rs.

Example from the rule's tests
import re a = re.compile(r"[a-z_a]+")tx0 reports: the character a appears twice in a character classb = re.compile(r"[0-9.,.]")tx0 reports: the character . appears twicec = re.compile(r"[a-zA-Z0-9_\-]")d = re.compile(r"[\d\s]")
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/python:regex-duplicate-class-member" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

# tx0: ignore[tx0/python:regex-duplicate-class-member] reason="..."

tx0 explain tx0/python:regex-duplicate-class-member shows the same in the terminal. Found a false positive? Report it.