Skip to content

Merge isinstance

Documentation Index

Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt

Use this file to discover all available pages before exploring further.

Combines together multiple isinstance functions

if isinstance(hat, Bowler) or isinstance(hat, Fedora):
wear(hat)
if isinstance(hat, (Bowler, Fedora)):
wear(hat)

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.