[Python-ideas] allow line break at operators

Nick Coghlan ncoghlan at gmail.com
Sun Sep 18 13:56:49 CEST 2011

On Sun, Sep 18, 2011 at 9:38 PM, Ben Finney <ben+python at benfinney.id.au> wrote:
> In other words: once I've come to a hypothesis from my reading of the
> grammar, how can I *verify* that against the actual running Python
> language parser?

To an arbitrary level, you can't. The ast module gets you pretty
close, though, since optimisations aren't applied when you request the
AST as the output of compilation:

# 3.2
>>> ast.dump(compile("'Hello ' 'World!'", "<ast>", "eval", flags=ast.PyCF_ONLY_AST))
"Expression(body=Str(s='Hello World!'))"
>>> ast.dump(compile("'Hello ' + 'World!'", "<ast>", "eval", flags=ast.PyCF_ONLY_AST))
"Expression(body=BinOp(left=Str(s='Hello '), op=Add(), right=Str(s='World!')))"

Not that even the AST is post the implicit string concatenation step, though.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list