Crimes with Python's Pattern Matching
Today, I learn some wired tricks in Python's pattern matching :lol:
You can match on arrays, dictionaries, and custom objects. To support matching objects, Python uses
isinstance(obj, class), which checks
- If
objis of typeclass- If
objis a transitive subtype ofclass- If
classis an ABC and defines a__subclasshook__that matches the type ofobj.