berkerpeksag / astor

Python AST read/write
https://pypi.org/project/astor/
BSD 3-Clause "New" or "Revised" License
810 stars 102 forks source link

Yield fixes #31

Closed pmaupin closed 9 years ago

pmaupin commented 9 years ago

It turns out the cheezy way I did yield fixes before was no good, because it is legal to do (yield foo)(bar).

The new way always encloses yield statements in parentheses. This is ugly, and MAY not (I don't know) work on earlier versions, although it works fine on 2.7.

So it fixes a known bug (behavior actually occurs in a library), but might break < 2.7. Probably the right thing to do for now.

berkerpeksag commented 9 years ago

I personally don't care about Python 2.6 and older versions :) So the patch LGTM. Perhaps we can add a TODO or XXX note to the code so we don't forget to improve the "The new way always encloses yield statements in parentheses." part in the future.

pmaupin commented 9 years ago

It's a plan. In fact, it really is a plan -- I've been working on code that looks at precedence and gets rid of all unnecessary parentheses in the generated Python. :-)

berkerpeksag commented 9 years ago

@pmaupin ah great! So I'll merge this for now.

berkerpeksag commented 9 years ago

Thanks!