You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PLR1701 will merge repeated isinstance calls and also rewrite literal tuples into unions for modern Python versions. But an isinstance check with a variable bound tuple will also be merged into the union, and that will cause a TypeError at runtime.
This especially interacts badly with SIM114 where you could have defined two if arms, one with a variable bound tuple, and one with a literal tuple, and it'll get merged and wrongly rewritten as a union. Example below.
Actually, isinstance(None, (TYPES, set | float)) is safe... so in theory we could always rewrite to the tuple variant if we can't be certain that | will work?
PLR1701
is mentioned in passing in #10245.PLR1701
will merge repeatedisinstance
calls and also rewrite literal tuples into unions for modern Python versions. But anisinstance
check with a variable boundtuple
will also be merged into the union, and that will cause aTypeError
at runtime.This especially interacts badly with
SIM114
where you could have defined twoif
arms, one with a variable boundtuple
, and one with a literaltuple
, and it'll get merged and wrongly rewritten as a union. Example below.Ruff 0.45
pyproject.toml
:ruff check --select SIM114,PLR1701 --fix
actual
The text was updated successfully, but these errors were encountered: