mirror of
https://github.com/python/cpython.git
synced 2025-10-09 08:31:26 +00:00
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>
This commit is contained in:
parent
cc02b4f2e8
commit
145bf269df
43 changed files with 10867 additions and 2607 deletions
|
@ -152,6 +152,15 @@ __all__ = ['dataclass',
|
|||
#
|
||||
# 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue