[Python-Dev] Re: PEP 622: Structural Pattern Matching

2020年6月24日 08:29:33 -0700

On Wed, Jun 24, 2020 at 4:05 AM Greg Ewing <[email protected]>
wrote:
> On 24/06/20 11:57 am, Guido van Rossum wrote:
> > Matched key-value pairs must already be present in the mapping, and not
> > created
> > on-the-fly by ``__missing__`` or ``__getitem__``. For example,
> > ``collections.defaultdict`` instances will only match patterns with keys
> > that
> > were already present when the ``match`` block was entered.
>
> Does that mean the pattern matching logic is in cahoots with
> collections.defaultdict? What if you want to match against
> your own defaultdict-like type?
>
IIUC the pattern matching uses either .get(key, <sentinel>) or
.__contains__(key) followed by .__getitem__(key). Neither of those will
auto-add the item to a defaultdict (and the Mapping protocol supports
both). @Brandt: what does your implementation currently do? Do you think we
need to specify this in the PEP?
-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
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/OIYPFZL2Q3XYCKAJQHLVPQ6MTZM5T32U/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to