Help me understand this

Neil Cerutti horpner at yahoo.com
Tue Jan 30 19:33:26 CET 2007


On 2007-01-30, Gabriel Genellina <gagsl-py at yahoo.com.ar> wrote:
> En Tue, 30 Jan 2007 06:34:01 -0300, Beej <beej at beej.us> escribió:
>
>> But here's one I still don't get:
>>
>>>>> type(2)
>> <type 'int'>
>>>>> type((2))
>> <type 'int'>
>>>>> (2).__add__(1)
>> 3
>>>>> 2.__add__(1)
>>   File "<stdin>", line 1
>>     2.__add__(1)
>>             ^
>> SyntaxError: invalid syntax
>
> It appears to be a bug, either in the grammar implementation, or in the  
> grammar documentation.
> These are the relevant rules:
>
> attributeref ::= primary "." identifier
>
> primary ::= atom | attributeref | subscription | slicing | call
>
> atom ::= identifier | literal | enclosure
>
> literal ::= stringliteral | integer | longinteger | floatnumber |  
> imagnumber
>
> An integer is a primary so 2.__add(1) should be valid.

Not if the tokenizer passes the parser a float.

-- 
Neil Cerutti



More information about the Python-list mailing list