On Sun, 3 Jan 2021 16:19:01 +0000
Barry Scott <ba...@barrys-emacs.org> wrote:
> > 
> > I’ll also quote the example match statement from the PEP abstract,
> > which extracts “host” and “port” details from a 2 item sequence, a
> > mapping with “host” and “port” keys, any object with “host” and “port”
> > attributes, or a “host:port” string, treating the “port” as optional
> > in the latter three cases:
> > 
> >    port = DEFAULT_PORT
> >    match expr:
> >        case [as host, as port]:
> >            pass
> >        case {"host" as host, "port" as port}:
> >            pass
> >        case {"host" as host}:
> >            pass
> >        case object{.host as host, .port as port}:
> >            pass
> >        case object{.host as host}:
> >            pass
> >        case str{} as addr:
> >            host, __, optional_port = addr.partition(":")
> >            if optional_port:
> >                port = optional_port
> >        case __ as m:
> >            raise TypeError(f"Unknown address format: {m!r:.200}")
> >    port = int(port)  
> 
> I read the above and believe I know what it meant without needing to read the 
> PEP in detail.
> I like that a lot.

+1.  Unlike the other PEP, there is no confusion with regular Python
syntax such as function calls.

Regards

Antoine.

_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/23DGXSXJ32DMJMZIETSEWGYDX2RNIR3W/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to