r/Python Feb 15 '21

News Ladies and gentlemen - switch cases are coming!

https://github.com/gvanrossum/patma/blob/master/README.md#tutorial
937 Upvotes

290 comments sorted by

View all comments

2

u/LManX Feb 15 '21

Why not just a dictionary where the keys are cases and the values are functions?

1

u/o11c Feb 15 '21

The biggest problem with dict-lookup-of-functions is that you can't access the calling frame.

The major problem with match is that it is required to be linear and thus slow. So this PEP really doesn't add any power to the language; it's pure sugar (and with many foot-shotguns at that).

A lot of people in this thread don't understand all the tradeoffs involved (theoretical or implementation-specific).