PEP 637: Allow empty starred arguments (GH-1744)

Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
This commit is contained in:
Stefano Borini 2020-12-23 18:43:35 +00:00 committed by GitHub
parent fc43230308
commit 831e7256d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 4 deletions

View File

@ -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: 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 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:: The following notation equivalence should be honored::
obj[*()] obj[*()]
# Error. Equivalent to obj[] # Equivalent to obj[()]
obj[*(), foo=3] obj[*(), foo=3]
# Equivalent to 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:: The following notation equivalent should be honored::
obj[**{}] obj[**{}]
# Error. Equivalent to obj[] # Equivalent to obj[()]
obj[3, **{}] obj[3, **{}]
# Equivalent to obj[3] # Equivalent to obj[3]
@ -838,6 +838,14 @@ make the dictionary type accept it automatically, to insert or refer to the valu
the empty tuple as key. Moreover, a typing notation such as ``Tuple[]`` can easily 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 Sentinel value for no given positional index
-------------------------------------------- --------------------------------------------