Guido van Rossum wrote:
> 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?

I still prefer under-specifying rather than over-specifying, in order to allow 
the implementation some flexibility. Basically, "if you've got a funny mapping, 
it may behave funny".

For example, we currently perform a length check before even getting to this 
point, which is allowed because the spec isn't very strict. This is a good 
thing; we already have a section in the PEP that explicitly allows compiler to 
perform transformations such as C(x) | C(y) -> C(x | y).

If we have to specify it, __contains__ followed by __getitem__ is the way to do 
it. The current behavior is subtly different (and probably wrong), but I was 
going to change it today anyways... I had an outstanding TODO for it.
_______________________________________________
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/FGHL3HV3Z5W5DBURTE76WU4YI23IRZ3Z/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to