An re flag is passed where re.sub or re.split take a count

tx0/python:regex-flag-as-countdefaultwarningbug

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.

Example from the rule's tests
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
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 in every tier. To turn it off for a project, set its level in tx0.toml:

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.