An re flag is passed where re.sub or re.split take a count
What it finds
re.sub(pattern, repl, text, re.IGNORECASE): the fourth positional argument of re.sub is count, not flags, so the flag is taken as a number, 2, and limits the replacements instead of changing the matching. re.split alike takes maxsplit third. Passing flags= by keyword says what was meant.
From the rule's source, regex_flag_as_count.rs.
import re def clean(text): a = re.sub(r"\s+", " ", text, re.IGNORECASE)tx0 reports: re.IGNORECASE is taken as count here, not as a flag b = re.split(r",", text, re.M)tx0 reports: re.M is taken as maxsplit here c = re.sub(r"\s+", " ", text, flags=re.I) d = re.sub(r"\s+", " ", text, 1) return a, b, c, d Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/python:regex-flag-as-count" = "off"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-flag-as-count] reason="..."tx0 explain tx0/python:regex-flag-as-count shows the same in the terminal. Found a false positive? Report it.