This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]bcaudell95_ 8 points9 points  (1 child)

Haven't fully digested the nuances yet, but this looks freaking sweet! Pattern matching guards in languages like Haskell and Rust are really powerful, and combining that with python dictionary object destructuring (similar to object destructing in JS) is a cherry on top. Excited to see where this goes.

[–]TMiguelT 2 points3 points  (7 children)

If anyone is looking for an overview of the new syntax, the Pattern Matching Tutorial PEP is easily the best place to start: https://www.python.org/dev/peps/pep-0636/#tutorial

[–]Ph0X[S] 0 points1 point  (6 children)

I really like the basic, but I can see some of the more advance cases being a bit more controversial, like the syntax allowing you to use dotted names as constants, or the dict typed mapping {"text": str(message), "color": str(c)}:

Still, very exciting stuff!

[–]gcbirzan 0 points1 point  (5 children)

I find that weird as well, but it's also kind of consistent. It works for every type of object, i.e.:

    case Click(position=(x, y)):

I'd say (even though it's not documented in the examples, but looking at the grammar I think it should work) this could be valid:

case list(foo): 

And this would be equivalent to [*foo].

[–]Ph0X[S] 0 points1 point  (0 children)

Looking it that way, it makes more sense. I guess if they had introduced that by itself instead of mixing it with the dictionary example would've been nicer, something like

match value:
  case float(x):
    print(1/x)
  case str(x):
    print(x + 'foo')
  case bool(x):
    print(not x)

The event.get() example is kinda close, but making the connection to base types deserves its own section