pylint should warn about type(x) == Y
and type(x) is Y
#299
Labels
Enhancement ✨
Improvement to a component
type(x) == Y
and type(x) is Y
#299
Originally reported by: Chris Rebert (BitBucket: cvrebert, GitHub: @cvrebert?)
People who are new to Python often forget that the
isinstance()
built-in function exists, and instead end up writing their typechecks non-idiomatically, usingtype()
and an equality comparison. Here's an example:pylint doesn't currently emit any relevant warnings for this code. I propose it should emit warnings suggesting that the code be rewritten to use
isinstance()
instead.Corrected example:
(Yes, I know that these aren't strictly equivalent due to subclasses and metaclasses, but those cases are pretty uncommon.)
The text was updated successfully, but these errors were encountered: