mirror of
https://github.com/python/cpython.git
synced 2025-11-03 11:23:31 +00:00
gh-106780: Add __match_args__ to tutorial example (#106784)
Add Point definition with this attribute before example that needs it.
This commit is contained in:
parent
babb22da5a
commit
7aa89e505d
1 changed files with 7 additions and 1 deletions
|
|
@ -343,7 +343,13 @@ Dotted names (like ``foo.bar``), attribute names (the ``x=`` and ``y=`` above) o
|
||||||
(recognized by the "(...)" next to them like ``Point`` above) are never assigned to.
|
(recognized by the "(...)" next to them like ``Point`` above) are never assigned to.
|
||||||
|
|
||||||
Patterns can be arbitrarily nested. For example, if we have a short
|
Patterns can be arbitrarily nested. For example, if we have a short
|
||||||
list of points, we could match it like this::
|
list of Points, with ``__match_args__`` added, we could match it like this::
|
||||||
|
|
||||||
|
class Point:
|
||||||
|
__match_args__ = ('x', 'y')
|
||||||
|
def __init__(self, x, y):
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
|
||||||
match points:
|
match points:
|
||||||
case []:
|
case []:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue