[Python-ideas] PEP pre-draft: Support for indexing with keyword arguments

Nick Coghlan ncoghlan at gmail.com
Wed Jul 2 09:06:53 CEST 2014


On 1 July 2014 15:36, Stefano Borini <stefano.borini at ferrara.linux.it> wrote:
> Dear all,
>
> after the first mailing list feedback, and further private discussion with
> Joseph Martinot-Lagarde, I drafted a first iteration of a PEP for keyword
> arguments in indexing. The document is available here.
>
> https://github.com/stefanoborini/pep-keyword/blob/master/PEP-XXX.txt
>
> The document is not in final form when it comes to specifications. In fact,
> it requires additional discussion about the best strategy to achieve the
> desired result. Particular attention has been devoted to present alternative
> implementation strategies, their pros and cons. I will examine all feedback
> tomorrow morning European time (in approx 10 hrs), and apply any pull
> requests or comments you may have.

It's a well written PEP, but the "just use call notation instead"
argument is going to be a challenging one to overcome.

Given that part of the rationale given is that "slice(start, stop,
step)" is uglier than the "start:stop:step" permitted in an indexing
operation, the option of allowing "[start:]",
"[:stop]","[start:stop:step]", etc as dedicated slice syntax should
also be explicitly considered.

Compare:

    a.get(slice(1,3), Z=2) # today
    a.get([1:3], Z=2) # slice sytax
    a[1:3, Z=2] # PEP

Introducing a more general slice notation would make indexing *less*
special (reducing the current "allows slice notation" special case to
"allows slice notation with the surrounding square brackets implied".

The reduction of special casing could be taken further, by allowing
the surrounding square brackets to be omitted in tuple and list
displays, just as they are in indexing operations.

I'm not saying such a proposal would necessarily be accepted - I just
see a proposal that takes an existing special case and proposes to
make it *less* special as more appealing than one that proposes to
make it even *more* special.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list