This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients lukasz.langa, serhiy.storchaka
Date 2018-05-12.22:22:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1526163754.81.0.682650639539.issue33475@psf.upfronthosting.co.za>
In-reply-to
Content
The proposed patch fixes bugs in ast_unparse.c, makes it generating cleaner string representation, and makes the code cleaner.

Known fixed bugs:

1. Extended slices crash Python. "s[a, b:c]".

2. 1-tuples produce illegal syntax: "(a,)" => "(, a)".

3. Lambdas in f-strings produce illegal syntax. "f'{(lambda x: x)}'" => "f'{lambda x: x}'".

4. Some expressions that need parenthesis don't have them. E.g. "lambda x: (x, x)" => "lambda x: x, x".

5. Generators and yield expression always must be surrounded with parenthesis. "(x for x in y)" => "x for x in y", "(yield)" => "yield".

6. Top-level tuples must be surrounded with parenthesis. "(a, b)" => "a, b".

Produced string representation is now more clean and almost not contains redundant parenthesis.

"(a + b) * (c + d)" => "(a + b) * (c + d)"
"(a * b) + (c * d)" => "a * b + c * d"
"(a * b) * (c * d)" => "a * b * (c * d)"
"(a ** b) ** (c ** d)" => "(a ** b) ** c ** d"
"[(a + b)]" => "[a + b]"
"[(i ** 2) for i in range(1, (a + 1))]" => "[i ** 2 for i in range(1, a + 1)]"

Maybe other bugs were fixed in process.

And finally I use macros for simple repeated fragments of code like

        if (-1 == append_charp(writer, str)) {
            return -1;
        }

This made the meaningful code much shorter and saved around 250 lines of code.
History
Date User Action Args
2018-05-12 22:22:34serhiy.storchakasetrecipients: + serhiy.storchaka, lukasz.langa
2018-05-12 22:22:34serhiy.storchakasetmessageid: <1526163754.81.0.682650639539.issue33475@psf.upfronthosting.co.za>
2018-05-12 22:22:34serhiy.storchakalinkissue33475 messages
2018-05-12 22:22:34serhiy.storchakacreate