8
iamrp
5d

The creators of the Python language are giving some thought to a new proposition, PEP 622, that would finally bring a Pattern Matching statement structure to Python. PEP 622 proposes a method for matching an expression against various kinds of patterns using a match/case (simply like switch/case in C) language structure :

match some_expression:
case pattern_1:
...
case pattern_2:
...

It includes literals, names, constant values, mapping, a class or a mixture of the above.

Source : https://python.org/dev/peps/...

Comments
  • 5
    Even though it's common, I don't like the explicit "case" syntax. It's fairly obvious when you're entering a discriminator. Given that, it's just ceremony. I don't find value in the added explicitness, preferring instead an ocaml-style approach that minimizes tedious symbolic prefixing.

    Ex: Give keyword match, I know I can expect the next child indented case to be a case statement, if it's not, compiler error.

    That said, I fully support adding pattern matching to basically everything.

    *https://www2.lib.uchicago.edu/keith....
  • 3
    Looks like switch case.
    Still waiting for do while loop 😂
  • 1
    I think this is quite fitting:
    https://charlesleifer.com/blog/...

    Like, fuck, shit like numba should be integrated into python.
    Pip is so broken.
    But oh, I have an idea, let's implement a half baked, slow as shit match statement that looks like a switch ! Who cares if a usage takes 1 full second to get printed.
  • 1
    I don't want to be rude, but they'd better propose common comments and annotations syntax, because I can't seem to make simple comment appear for variable and it's a pain in ass to constantly switch between files just to see if there is any comment above class property. Though with functions it seems to work all well if I place comment in its body...
  • 2
    @vintprox comment...? What? I have no idea what you're talking about at the moment and i'm concerned you may be having a legit issue that can be resolved.
  • 1
    So if I read correctly, this is a statement, not an expression?

    Fuck that, go back to the cave whence you came.
Add Comment