On Fri, Sep 25, 2020 at 11:50 PM Steven D'Aprano <steve@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:


would be a SyntaxError,



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.


Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython