Lack of whitespace between contain operator ("in") and other expression tokens doesn't result in SyntaxError: bug or feature?

Garrett Cooper yanegomi at gmail.com
Thu May 3 15:21:05 EDT 2012


On Thu, May 3, 2012 at 12:03 PM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Thu, May 3, 2012 at 12:49 PM, Garrett Cooper <yanegomi at gmail.com> wrote:
>>    I was wondering whether this was a parser bug or feature (seems
>> like a bug, in particular because it implicitly encourages bad syntax,
>> but I could be wrong). The grammar notes (for 2.7 at least [1]) don't
>> seem to explicitly require a space between 'in' and another parser
>> token (reserved work, expression, operand, etc), but I could be
>> misreading the documentation.
>
> The grammar doesn't require whitespace there.  It tends to be flexible
> about whitespace wherever it's not necessary to resolve ambiguity.
>
>>>> x = [3, 2, 1]
>>>> x [0]if x [1]else x [2]
> 3
>>>> 1 . real
> 1
>>>> 1.5.real
> 1.5

    Sure.. it's just somewhat inconsistent with other expectations in
other languages, and seems somewhat unpythonic.
    Not really a big deal (if it was I would have filed a bug
instead), but this was definitely a bit confusing when I ran it
through the interpreter a couple of times...
Thanks!
-Garrett



More information about the Python-list mailing list