0 + not 0

Mark Lawrence breamoreboy at yahoo.co.uk
Sat Jul 11 16:05:13 EDT 2015


On 11/07/2015 17:56, Ian Kelly wrote:
> On Sat, Jul 11, 2015 at 10:02 AM, Stefan Ram <ram at zedat.fu-berlin.de> wrote:
>>    I look at Python 3.4.3:
>>
>> a_expr ::=  m_expr | a_expr "+" m_expr | a_expr "-" m_expr
>>
>>    So, »not 0« must be an »m_expr« when used as the right operand of »+«.
>>
>> m_expr ::=  u_expr | m_expr "*" u_expr | m_expr "//" u_expr | m_expr "/" u_expr | m_expr "%" u_expr
>> u_expr ::=  power | "-" u_expr | "+" u_expr | "~" u_expr
>> power ::=  primary ["**" u_expr]
>> primary ::=  atom | attributeref | subscription | slicing | call
>> atom      ::=  identifier | literal | enclosure
>> enclosure ::=  parenth_form | list_display | dict_display | set_display | generator_expression | yield_atom
>>
>>    How can there be a »not«?
>>
>>    »not« is used in
>>
>> not_test ::=  comparison | "not" not_test
>> and_test ::=  not_test | and_test "and" not_test
>> or_test  ::=  and_test | or_test "or" and_test
>> conditional_expression ::=  or_test ["if" or_test "else" expression]
>> expression_nocond      ::=  or_test | lambda_expr_nocond
>> expression             ::=  conditional_expression | lambda_expr
>>
>>    , but an »expression« is not an »m_expr«.
>
> I must concur. The grammar as written does not actually produce 1 +
> not 0. I think it's still worthwhile opening a bug, because the
> behavior is surprising and possibly not intentional.
>

http://bugs.python.org/issue24612

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence




More information about the Python-list mailing list