"Data blocks" syntax specification draft

Ian Kelly ian.g.kelly at gmail.com
Wed May 23 02:06:33 EDT 2018


On Wed, May 23, 2018 at 12:01 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Tue, May 22, 2018 at 11:32 PM, Christian Gollwitzer <auriocus at gmx.de> wrote:
>> Am 23.05.18 um 07:22 schrieb Chris Angelico:
>>>
>>> On Wed, May 23, 2018 at 9:51 AM, bartc <bc at freeuk.com> wrote:
>>>>
>>>> Sorry, but I don't think you're right at all. unless the official
>>>> references
>>>> for the language specifically say that commas are primarily for
>>>> constructing
>>>> tuples, and all other uses are exceptions to that rule.
>>>
>>>
>>> "A tuple consists of a number of values separated by commas"
>>>
>>> https://docs.python.org/3/tutorial/datastructures.html#tuples-and-sequences
>>>
>>> "Separating items with commas"
>>> https://docs.python.org/3/library/stdtypes.html#tuple
>>>
>>> "Note that tuples are not formed by the parentheses, but rather by use
>>> of the comma operator."
>>> https://docs.python.org/3/reference/expressions.html#parenthesized-forms
>>>
>>> Enough examples? Commas make tuples, unless context specifies otherwise.
>>
>>
>> I'd think that the definitive answer is in the grammar, because that is what
>> is used to build the Python parser:
>>
>>         https://docs.python.org/3/reference/grammar.html
>>
>> Actually, I'm a bit surprised that tuple, list etc. does not appear there as
>> a non-terminal. It is a bit hard to find, and it seems that "atom:" is the
>> starting point for parsing tuples, lists etc.
>
> For enclosed tuples, yes. I believe that tuples without parentheses
> can be produced by either 'exprlist' or 'testlist' (which is why some
> cases permit iterable unpacking and some don't).

Er, that should be "either 'testlist_star_expr' or 'testlist'".



More information about the Python-list mailing list