Merge isinstance¶
Sourcery refactoring id: merge-isinstance
¶
Description:¶
Combines together multiple isinstance
functions
Before:¶
if isinstance(hat, Bowler) or isinstance(hat, Fedora):
wear(hat)
After:¶
if isinstance(hat, (Bowler, Fedora)):
wear(hat)
Explanation:¶
When you want to check whether something is one of multiple different types, you
can merge the two isinstance
checks into a single call.
This is shorter while staying nice and easy to read.