bpo-42128: Structural Pattern Matching (PEP 634) (GH-22917)

Co-authored-by: Guido van Rossum <guido@python.org>
Co-authored-by: Talin <viridia@gmail.com>
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py
index 0c4b475..422a95c 100644
--- a/Lib/dataclasses.py
+++ b/Lib/dataclasses.py
@@ -152,6 +152,15 @@
 #
 # See _hash_action (below) for a coded version of this table.
 
+# __match_args__
+#
+# |  no   |  yes  |  <--- class has __match_args__ in __dict__?
+# +=======+=======+
+# | add   |       |  <- the default
+# +=======+=======+
+# __match_args__ is always added unless the class already defines it. It is a
+# tuple of __init__ parameter names; non-init fields must be matched by keyword.
+
 
 # Raised when an attempt is made to modify a frozen class.
 class FrozenInstanceError(AttributeError): pass
@@ -1007,6 +1016,9 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen):
         cls.__doc__ = (cls.__name__ +
                        str(inspect.signature(cls)).replace(' -> NoneType', ''))
 
+    if '__match_args__' not in cls.__dict__:
+        cls.__match_args__ = tuple(f.name for f in flds if f.init)
+
     abc.update_abstractmethods(cls)
 
     return cls