| So it’s actually a smart switch statement. Seems like it doesn’t create instances when you’re doing Node(children=[Leaf(value="("), Node(), Leaf(value=")")])
instead:1. Node means "is instance of Node". 2. Everything in between () is "has an attribute with value". 3. List means "the attribute should be treated as a tuple of"..
etc.. Very confusing, this definitely needs another syntax, because both newcomers and experienced devs will be prone to read it as plain `==`, since that's how enums and primitives will be working. This syntax goes against Zen:
It’s implicit -- when using match case expressions don't mean what they regularly mean.
It’s complicated -- basically it’s another language (like regex) which is injected into Python. 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. match node:
case Node{children=[{Leaf{value="(", Node{}, ...}}
|
I understand the worry that newcomers might struggle, but I don't think it'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're proposing, it'd also be the odd one out among dozens of mainstream languages including this feature, which I think would be even more confusing!