Python: Acceptance of Pattern Matching – PEP 634

by potomakon 2/9/2021, 4:06 AMwith 12 comments

by JNRoweon 2/9/2021, 5:05 AM

Direct links to the PEPs themselves, to perhaps save others a little time.

Accepted:

Specification https://www.python.org/dev/peps/pep-0634/

Motivation and Rationale https://www.python.org/dev/peps/pep-0635/

Tutorial https://www.python.org/dev/peps/pep-0636/

Rejected:

Unused variable syntax https://www.python.org/dev/peps/pep-0640/

Explicit Pattern Syntax for Structural Pattern Matching https://www.python.org/dev/peps/pep-0642/

by pansa2on 2/9/2021, 6:17 AM

It's interesting that pattern matching has been accepted despite a poll showing a majority (65%) of core developers opposed to this particular proposal, and a plurality (44%) opposed to pattern matching altogether.

https://discuss.python.org/t/gauging-sentiment-on-pattern-ma...

by pansa2on 2/9/2021, 8:45 AM

Is it still the case that these two pieces of code have different behaviour?

    match status:
        case 404:
            return "Not found"

    not_found = 404
    match status:
        case not_found:
            return "Not found"
IIRC in an earlier proposal, the former would check for equality (`status == 404`) and the latter would perform an assignment (`not_found = status`).