[issue44276] Replace if-elif-else structure with match-case (PEP634)

Terry J. Reedy report at bugs.python.org
Fri Jun 4 16:54:54 EDT 2021


Terry J. Reedy <tjreedy at udel.edu> added the comment:

To me, Raymond's flattening is a plausible replacement, especially ater a future speedup.  However, I would re-order the patterns to None, False, True, str(), int(), ..., _.  These independent conditions, other than _ (or else in the if chain), can be ordered for best reading and comprehension speed, and I think the above is an improvement.

Ordering for execution speed would instead start with the most frequently true conditions.  An advantage of match over 'if' is that patterns are apparently easier to re-order or otherwise automatically optimize.

I agree that replacement should only be done when there is significant improvement in reading and/or execution speed.  To avoid backport issues, they should best be preceded by a check for bug reports and especially PRs that will or do affect the same area of code.

The proposal for a general, +- global replacement has been and will be rejected. I think that this issue should therefore be closed, fairly soon, as such.

----------
nosy: +terry.reedy

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44276>
_______________________________________


More information about the Python-bugs-list mailing list