"Structural pattern matching" for Python, part 2
"Structural pattern matching" for Python, part 2
Posted Sep 15, 2020 13:28 UTC (Tue) by udifuchs (guest, #141354)Parent article: "Structural pattern matching" for Python, part 2
match pt:
case Point2D(x, y):
It looks like the class is being initiated.
I was wondering if using square brackets would make more sense,
as it is similar to the syntax used for type annotations.
For example:
match pt:
case Point2D[x, y]:
One issue with this idea is that the square bracket use might be confused with
item access. In enum, for example, this is a valid syntax:
>>> Sides["SPAM"] == Sides.SPAM == Sides("Spam")
True
Resolving this conflict would probably require not allowing such item access
inside a case statement.
