Multiple issubclass calls

issubclass can take multiple types, so there is no need to call them multiple times for each type.

issubclass returns True if the first argument is an subclass of specified type/types (and a class is considered a subclass of itself).

Given that these result in the same outcome:

Why not choose the easiest to read, write, and execute (the first one)?

Note also that as of Python 3.10, issubclass also accepts Union Type:

If our GitHub code review bot spots this issue in your pull request it gives this advice:

code-review-doctorbotsuggested changes just now
validation.py
1
+
if isinstance(item, int) or isinstance(item, float):
Suggested changes
-
if isinstance(item, int) or isinstance(item, float):
+
if isinstance(item, (int, float)):
Commit suggestion

isinstance can take multiple types, so there is no need to call them multiple times for each type.

Read more
2
+
    pass
Update validation.py
We're your Python code review copilot. Get code improvements right in your pull request with our GitHub code review bot.

Configuring this check

Code Review Doctor will run this check by default. No configuration is needed but the check can be turned on/off using check code multiple-issubclass-calls in your pyproject.toml file.

Read more about configuring Code Review Doctor.