7 votes

Crimes with Python's Pattern Matching

1 comment

  1. onyxleopard
    Link
    ABCs are really neat, but also can make your Python code totally ungrokkable to others who try to use your code at a surface level without understanding your implementation. What this post shows...

    ABCs are really neat, but also can make your Python code totally ungrokkable to others who try to use your code at a surface level without understanding your implementation.

    What this post shows is not really that Python’s new pattern matching is dark magic, but that __subclasshook__ is dark magic. You’d have no idea about this unless you look into how the new pattern matching and subclassing interact. I’d compare this to other clever uses of Python dunder methods—it’s useful and elegant when used judiciously, but it’s anything but obvious.

    4 votes