There is a mistake in the tutorial,they have copy from PEP636 but forget the
So there see it's like this.
@dataclass
.So there see it's like this.
from dataclasses import dataclass @dataclass class Point: x: int y: int def where_is(point): match point: case Point(x=0, y=0): print("Origin") case Point(x=0, y=y): print(f"Y={y}") case Point(x=x, y=0): print(f"X={x}") case Point(): print("Somewhere else") case _: print("Not a point")Then it work as it should.
>>> point = Point(0, 0) >>> where_is(point) Origin >>> >>> point = Point(0, 9) >>> where_is(point) Y=9 >>> >>> point = Point(4, 0) >>> where_is(point) X=4 >>> >>> point = Point('hello', 'world') >>> where_is(point) Somewhere else