<story><title>PEP 622 – Structural Pattern Matching</title><url>https://www.python.org/dev/peps/pep-0622/</url></story><parent_chain><item><author>mdrachuk</author><text>So it’s actually a smart switch statement.&lt;p&gt;Seems like it doesn’t create instances when you’re doing&lt;p&gt;&lt;pre&gt;&lt;code&gt;  Node(children=[Leaf(value=&amp;quot;(&amp;quot;), Node(), Leaf(value=&amp;quot;)&amp;quot;)])
&lt;/code&gt;&lt;/pre&gt;
instead:&lt;p&gt;1. Node means &amp;quot;is instance of Node&amp;quot;.&lt;p&gt;2. Everything in between () is &amp;quot;has an attribute with value&amp;quot;.&lt;p&gt;3. List means &amp;quot;the attribute should be treated as a tuple of&amp;quot;..
etc..&lt;p&gt;Very confusing, this definitely needs another syntax, because both newcomers and experienced devs will be prone to read it  as plain `==`, since that&amp;#x27;s how enums and primitives will be working.&lt;p&gt;This syntax goes against Zen:
It’s implicit -- when using match case expressions don&amp;#x27;t mean what they regularly mean.
It’s complicated -- basically it’s another language (like regex) which is injected into Python.&lt;p&gt;I’m a big believer in this feature, it just needs some other syntax.
Using {} instead of () makes it a lot better. Now no way to confuse it with simple equality.&lt;p&gt;&lt;pre&gt;&lt;code&gt;  match node:
    case Node{children=[{Leaf{value=&amp;quot;(&amp;quot;, Node{}, ...}}&lt;/code&gt;&lt;/pre&gt;</text></item></parent_chain><comment><author>andolanra</author><text>It&amp;#x27;s worth noting that there&amp;#x27;s a &lt;i&gt;truly massive&lt;/i&gt; amount of precedent in other languages for Python implementing it using the syntax as proposed. Languages that have or are planning to include pattern-matching where the pattern syntax exactly mirrors the expression syntax like this include Rust, Swift, OCaml, Haskell, C++, Ruby, Erlang, and many, many more.&lt;p&gt;I understand the worry that newcomers might struggle, but I don&amp;#x27;t think it&amp;#x27;s going to be the case: newcomers regularly learn the languages listed above without stumbling across that problem. And if Python did choose a syntax like the one you&amp;#x27;re proposing, it&amp;#x27;d also be the odd one out among dozens of mainstream languages including this feature, which I think would be even &lt;i&gt;more&lt;/i&gt; confusing!</text></comment>
<story><title>PEP 622 – Structural Pattern Matching</title><url>https://www.python.org/dev/peps/pep-0622/</url></story><parent_chain><item><author>mdrachuk</author><text>So it’s actually a smart switch statement.&lt;p&gt;Seems like it doesn’t create instances when you’re doing&lt;p&gt;&lt;pre&gt;&lt;code&gt;  Node(children=[Leaf(value=&amp;quot;(&amp;quot;), Node(), Leaf(value=&amp;quot;)&amp;quot;)])
&lt;/code&gt;&lt;/pre&gt;
instead:&lt;p&gt;1. Node means &amp;quot;is instance of Node&amp;quot;.&lt;p&gt;2. Everything in between () is &amp;quot;has an attribute with value&amp;quot;.&lt;p&gt;3. List means &amp;quot;the attribute should be treated as a tuple of&amp;quot;..
etc..&lt;p&gt;Very confusing, this definitely needs another syntax, because both newcomers and experienced devs will be prone to read it  as plain `==`, since that&amp;#x27;s how enums and primitives will be working.&lt;p&gt;This syntax goes against Zen:
It’s implicit -- when using match case expressions don&amp;#x27;t mean what they regularly mean.
It’s complicated -- basically it’s another language (like regex) which is injected into Python.&lt;p&gt;I’m a big believer in this feature, it just needs some other syntax.
Using {} instead of () makes it a lot better. Now no way to confuse it with simple equality.&lt;p&gt;&lt;pre&gt;&lt;code&gt;  match node:
    case Node{children=[{Leaf{value=&amp;quot;(&amp;quot;, Node{}, ...}}&lt;/code&gt;&lt;/pre&gt;</text></item></parent_chain><comment><author>masklinn</author><text>&amp;gt; Very confusing, this definitely needs another syntax&lt;p&gt;The entire point of structural pattern matching is that structuring and destructuring look the same.&lt;p&gt;&amp;gt; This syntax goes against Zen: It’s implicit -- when using match case expressions don&amp;#x27;t mean what they regularly mean.&lt;p&gt;There&amp;#x27;s nothing implicit to it. The match&amp;#x2F;case tells you that you&amp;#x27;re in a pattern-matching context.&lt;p&gt;&amp;gt; I’m a big believer in this feature, it just needs some other syntax. Using {} instead of () makes it a lot better. Now no way to confuse it with simple equality.&lt;p&gt;Makes it even better by… looking like set literals and losing the clear relationship between construction and deconstruction?</text></comment>