Two functions of a file have the same body
What it finds
Two functions with the same body, token for token, are a copy that will drift: a fix to one is easily missed in the other. One can call the other, or both can share a helper. Compared are bodies with at least min-lines statements directly in them; methods are compared within their class and module-level functions with each other. The later function is reported.
From the rule's source, duplicate_function_body.rs.
def load_users(db): rows = db.query("users") rows.sort() return rows def load_admins(db):tx0 reports: this function has the same body as load_users rows = db.query("users") rows.sort() return rows def short_a(x): return x def short_b(x): return x Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/python:duplicate-function-body" = "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:duplicate-function-body] reason="..."tx0 explain tx0/python:duplicate-function-body shows the same in the terminal. Found a false positive? Report it.