On Fri, Sep 25, 2020 at 11:50 PM Steven D'Aprano <st...@pearwood.info>
wrote:
>>
>> 1. We have to pass a sentinel to the setitem dunder if there is no
>> positional index passed.


I still don't follow this logic -- why can't nothing be passed? The dunders
either require an index or they don't, would that be just like function
calling? So (adapting the example in the PEP:

obj[spam=1, eggs=2]
# calls type(obj).__getitem__(obj, spam=1, eggs=2)

This sure seems like the obvious way to handle it. If the class requires a
positional argument
then it will fail with a TypeError.

This sure seems like the most straightforward way to handle it.

I'm sure I'm missing something, but reading the PEP, and my own experiments
haven't clarified it for me.

NOTE: one inconsistency would be that:

obj[]

would be a SyntaxError,

and

obj[this=x]

would be a TypeError, if a positional index were expected. but that's less
weird to me than the other incionsisentcies we are introducing for backward
compatibility.

-CHB

--
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/VPOSVVWAVZMW6BEUOCDYKY6GSJN4K6KV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to