[Python-Dev] Re: The semantics of pattern matching for Python

2020年11月22日 17:24:37 -0800

On 11/22/20 5:00 PM, Jim J. Jewett wrote:
I think your changed constructor:
class Car:
 def __init__(self, manufacturer, variant):
 self.brand = manufacturer
 self.model = variant
is a particularly good example, and the PEP should specify whether:
 Car("Chrysler", "PT Cruiser")
is matched by:
 Car(brand="Chrysler", mod:=model)
or:
 Car(manufacturer="Chrysler", mod:=variant)
or both, or possibly even Frankenstein combinations like:
 Car(brand="Chrysler", mod:=variant)
It could be a good example to include to emphasize that pattern matching is based on attributes, not function headers -- so `brand` and `model` would work, whilst `manufacturer` and `variant` would not.
--
~Ethan~
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/EO2XDZT52MCLNNJUV3PC2HFNC5BWJMUW/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to