On Fri, Sep 25, 2020 at 6:05 AM Ricky Teachey <ricky@teachey.org> wrote:
I'd like to hear more about why the empty tuple has been selected as the default index. 

It makes sense to me: if more than one index is passed, they are passed as a tuple. so many classes need to handle tuples anyway.

What other options are there? I suppose None is a possibility, but None is a valid dict key, so probably not a great idea. Hmm, so is an empty tuple. Darn.

I think having no default is a better option, as someone pointed out already in this thread.

-CHB




 

On Fri, Sep 25, 2020, 1:07 AM David Mertz <mertz@gnosis.cx> wrote:
Is this a breaking change? It feels borderline.

Keyword-only subscripts are permitted. The positional index will be the empty tuple:
obj[spam=1, eggs=2]
# calls type(obj).__getitem__(obj, (), spam=1, eggs=2)

I.e. consider:

>>> d = dict()
>>> d[()] = "foo"
>>> d
{(): 'foo'}
 
I don't really object to this fact, and one could argue it's not a breaking change since a built-in dict will simply raise an exception with keyword arguments.  However, it does make the empty tuple the "default key" for new objects that will accept keyword indices.

--
The dead increasingly dominate and strangle both the living and the
not-yet born.  Vampiric capital and undead corporate persons abuse
the lives and control the thoughts of homo faber. Ideas, once born,
become abortifacients against new conceptions.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@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/65KCDFYRUWH6K4HHMZT4UJTPDLE7JOPK/
Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@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/C4JVKD2ZUXU2Z6FDJOMHD5YYTACIHEIO/
Code of Conduct: http://python.org/psf/codeofconduct/


--
Christopher Barker, PhD

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