[RELEASE] Python 3.9.0a6 is now available for testing

Paul Moore p.f.moore at gmail.com
Wed Apr 29 18:13:24 EDT 2020


    m[-1]!= '\n'and'\n'or'  '

This is

    '\n' if m[-1] != '\n' else ' '

... just written in a way that was common before the if-expression was
invented, using and and or. In itself, it's fine.

The problem is that the space in "and '\n'" is omitted (presumably for
brevity for some reason?) leaving us with and'\n', which looks like a
string prefix (similar to r'\n' or f'\n') but with a prefix of "and"
which isn't a valid string prefix. The problem is that something isn't
disambiguating this the same way as the 3.8 parser did (I'd say it's
the "new parser" but Robin showed the same behaviour with "-X
oldparser" which makes me wonder...

Anyway, that's what I think is going on. I'll leave it to the parser
experts to understand what's happening and decide on a fix :-)

Paul

On Wed, 29 Apr 2020 at 20:54, Rhodri James <rhodri at kynesim.co.uk> wrote:
>
> On 29/04/2020 20:23, Schachner, Joseph wrote:
> >>      norm=lambda m: m+(m and(m[-1]!= '\n'and'\n'or'  ')or'\n')
> > Parentheses                       1          2                                        1         0
> > quotes                                                             1  0     1   0   1 0    1  0
> >
> > OK I don't see any violation of quoting or parentheses matching.   Still trying to figure out what this lambda does.
>
> Presumably it's something to do with recognising string prefixes?
>
> --
> Rhodri James *-* Kynesim Ltd
> --
> https://mail.python.org/mailman/listinfo/python-list


More information about the Python-list mailing list