PEP 637: Allow empty starred arguments (GH-1744)
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
This commit is contained in:
parent
fc43230308
commit
831e7256d5
16
pep-0637.rst
16
pep-0637.rst
|
@ -290,7 +290,7 @@ example use case 1, where a slice is accepted.
|
|||
|
||||
The successful implementation of this PEP will result in the following behavior:
|
||||
|
||||
1. An empty subscript is still illegal, regardless of context::
|
||||
1. An empty subscript is still illegal, regardless of context (see Rejected Ideas)::
|
||||
|
||||
obj[] # SyntaxError
|
||||
|
||||
|
@ -394,7 +394,7 @@ The successful implementation of this PEP will result in the following behavior:
|
|||
The following notation equivalence should be honored::
|
||||
|
||||
obj[*()]
|
||||
# Error. Equivalent to obj[]
|
||||
# Equivalent to obj[()]
|
||||
|
||||
obj[*(), foo=3]
|
||||
# Equivalent to obj[foo=3]
|
||||
|
@ -414,7 +414,7 @@ The successful implementation of this PEP will result in the following behavior:
|
|||
The following notation equivalent should be honored::
|
||||
|
||||
obj[**{}]
|
||||
# Error. Equivalent to obj[]
|
||||
# Equivalent to obj[()]
|
||||
|
||||
obj[3, **{}]
|
||||
# Equivalent to obj[3]
|
||||
|
@ -836,7 +836,15 @@ This proposal already established that, in case no positional index is given, th
|
|||
passed value must be the empty tuple. Allowing for the empty index notation would
|
||||
make the dictionary type accept it automatically, to insert or refer to the value with
|
||||
the empty tuple as key. Moreover, a typing notation such as ``Tuple[]`` can easily
|
||||
be written as ``Tuple`` without the indexing notation.
|
||||
be written as ``Tuple`` without the indexing notation.
|
||||
|
||||
However, subsequent discussion with Brandt Bucher during implementation has revealed
|
||||
that the case ``obj[]`` would fit a natural evolution for variadic generics, giving
|
||||
more strength to the above comment. In the end, after a discussion between D'Aprano,
|
||||
Bucher and the author, we decided to leave the ``obj[]`` notation as a syntax
|
||||
error for now, and possibly extend the notation with an additional PEP to hold
|
||||
the equivalence ``obj[]`` as ``obj[()]``.
|
||||
|
||||
|
||||
Sentinel value for no given positional index
|
||||
--------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue