You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I fixed the code as follows since points is not defined, still it does not work:
classPoint:
def__init__(self, x, y):
self.x=xself.y=ypoints= [Point(0,7), Point(0,9)]
matchpoints:
case []:
print("No points")
case [Point(0, 0)]:
print("The origin")
case [Point(x, y)]:
print(f"Single point {x}, {y}")
case [Point(0, y1), Point(0, y2)]:
print(f"Two on the Y axis at {y1}, {y2}")
case _:
print("Something else")
error:
Traceback (most recent call last):
File "c:\Users\moham\OneDrive\Education\UDST\gpaCal.py", line 15, in <module>
case [Point(0, y1), Point(0, y2)]:
^^^^^^^^^^^^TypeError: Point() accepts 0 positional sub-patterns (2 given)
That Point definition is in a previous example. The paragraph that follows explains the solution for matching positional parameters. In this case, add __match_args__ = ('x', 'y') to Point and the example works. I will augment the Point list example with a proper Point definition. Working on PR.
Activity
terryjreedy commentedon Jul 15, 2023
That Point definition is in a previous example. The paragraph that follows explains the solution for matching positional parameters. In this case, add
__match_args__ = ('x', 'y')to Point and the example works. I will augment the Point list example with a proper Point definition. Working on PR.pythongh-106780: Add __match_args__ to tutorial example
gh-106780: Add __match_args__ to tutorial example (#106784)
pythongh-106780: Add __match_args__ to tutorial example (pythonGH-106784
pythongh-106780: Add __match_args__ to tutorial example (pythonGH-106784
[3.11] gh-106780: Add __match_args__ to tutorial example (GH-106784) (#…
[3.12] gh-106780: Add __match_args__ to tutorial example (GH-106784) (#…