On Fri, Aug 28, 2020 at 4:30 AM Stephen J. Turnbull <
turnbull.stephen...@u.tsukuba.ac.jp> wrote:

>  > tuple, or dict themselves.  So `mylist[99, default=4]` would still
>  > be a syntax error (or maybe a different exception).
>
> I don't think it can be a SyntaxError because you can't always know
> that mylist is a builtin list.  list.__getitem__(self, ...) gets
> called and it tells you "TypeError: __getitem__() takes no keyword
> arguments", as it does now.  (Just for the record.  I bet you realized
> that within nanoseconds of hitting "send". ;-)
>

I'm not nearly so clever :-).

I was thinking, hypothetically, that it's possible for dict.__getitem__()
to have code along the lines of:

    def __getitem__(self, index, **kws):
        if kws:
            raise SyntaxError("Keywords not allowed in dictionary index")
        # ... actual item getting ...

I'm not saying that's a good idea per se.  Hence my parenthetical.
Probably any extra check on every dict access is a needless slowdown
though.  I only thought of it because `mydict[foo=bar]` now raises a
SyntaxError, so raising something different would technically be a change
in behavior.

How do you folks feel about list.get and tuple.get (I expect many
> folks will think differently about these because tuples are
> immutable), and more generally Sequence.get?
>

-1 on Sequence.get.  -0.5 on tuple.get.


-- 
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-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/FEWWNMJHVXD42JCS2VZX2RDS66HBOOLY/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to