Checks for object type comparisons without using isinstance().
Why is this bad?
Do not compare types directly.
When checking if an object is a instance of a certain type, keep in mind
that it might be subclassed. For example, bool inherits from int, and
Exception inherits from BaseException.
Example
if type(obj) is type(1):
pass
if type(obj) is int:
pass
%
ruff rule E721
type-comparison (E721)
Derived from the pycodestyle linter.
What it does
Checks for object type comparisons without using
isinstance()
.Why is this bad?
Do not compare types directly.
When checking if an object is a instance of a certain type, keep in mind that it might be subclassed. For example,
bool
inherits fromint
, andException
inherits fromBaseException
.Example
Use instead: