$ cat sim101.py
assert (
job.only_on_instances is None
or isinstance(job.only_on_instances, list)
or isinstance(job.only_on_instances, set)
)
$ python -m ruff --select=SIM101 sim101.py
sim101.py:2:5: SIM101 [*] Multiple `isinstance` calls for expression, merge into a single call
Found 1 error.
[*] 1 potentially fixable with the --fix option.
$ python -m ruff --select=SIM101 sim101.py --fix --diff
--- sim101.py
+++ sim101.py
@@ -1,5 +1,3 @@
assert (
- job.only_on_instances is None
- or isinstance(job.only_on_instances, list)
- or isinstance(job.only_on_instances, set)
+ isinstance(job.only_on_instances, (list, set)) or job.only_on_instances is None
)
Would fix 1 error.
$ python -m ruff --version
ruff 0.0.292
Notice that the original code checked job.only_on_instances is None first, and Ruff's change puts it second instead.
It's harmless in this case, but in general this change could break working code that relies on short-circuit evaluation.
Notice that the original code checked
job.only_on_instances is Nonefirst, and Ruff's change puts it second instead.It's harmless in this case, but in general this change could break working code that relies on short-circuit evaluation.