isinstance or issubclass is given something other than classes to check against
What it finds
isinstance(value, "str"), isinstance(items, list[int]), isinstance(x, [int, float]): the second argument of isinstance and issubclass must be a class, a union, or a tuple of those. A string, a literal, a list, or a parameterized generic such as list[int] raises TypeError when the check runs.
From the rule's source, isinstance_bad_class.rs.
def check(value, kinds): if isinstance(value, 'str'):tx0 reports: isinstance raises TypeError for 'str', which is a string return 1 if isinstance(value, list[int]):tx0 reports: which is a parameterized generic return 2 if isinstance(value, [int, float]):tx0 reports: which is a list; a tuple is meant return 3 if issubclass(value, (int, "x")):tx0 reports: issubclass raises TypeError return 4 if isinstance(value, (int, float)) or isinstance(value, kinds) or isinstance(value, int | None): return 5 return 0 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:isinstance-bad-class" = "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:isinstance-bad-class] reason="..."tx0 explain tx0/python:isinstance-bad-class shows the same in the terminal. Found a false positive? Report it.