[issue33475] Fix converting AST expression to string and optimize parenthesis

2018-05-22 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33475] Fix converting AST expression to string and optimize parenthesis

2018-05-20 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:


New changeset b32f8897eafcf335f9e9899c5e622a0b27679437 by Serhiy Storchaka in 
branch '3.7':
[3.7] bpo-33475: Fix and improve converting annotations to strings. (GH-6774). 
(GH-6927)
https://github.com/python/cpython/commit/b32f8897eafcf335f9e9899c5e622a0b27679437


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33475] Fix converting AST expression to string and optimize parenthesis

2018-05-17 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

There are still problems with f-strings like f'''{"'"}''' => f'{"\'"}' 
(SyntaxError: f-string expression part cannot include a backslash). But this is 
a separate hard issue (issue33552).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33475] Fix converting AST expression to string and optimize parenthesis

2018-05-17 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
pull_requests: +6598

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33475] Fix converting AST expression to string and optimize parenthesis

2018-05-16 Thread Łukasz Langa

Łukasz Langa  added the comment:


New changeset 64fddc423fcbe90b8088446c63385ec0aaf3077c by Łukasz Langa (Serhiy 
Storchaka) in branch 'master':
bpo-33475: Fix and improve converting annotations to strings. (GH-6774)
https://github.com/python/cpython/commit/64fddc423fcbe90b8088446c63385ec0aaf3077c


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33475] Fix converting AST expression to string and optimize parenthesis

2018-05-14 Thread Guido van Rossum

Change by Guido van Rossum :


--
nosy:  -gvanrossum

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33475] Fix converting AST expression to string and optimize parenthesis

2018-05-12 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
nosy: +gvanrossum

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33475] Fix converting AST expression to string and optimize parenthesis

2018-05-12 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
keywords: +patch
pull_requests: +6462
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33475] Fix converting AST expression to string and optimize parenthesis

2018-05-12 Thread Serhiy Storchaka

New submission from Serhiy Storchaka :

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.

--
components: Interpreter Core
messages: 316439
nosy: lukasz.langa, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Fix converting AST expression to string and optimize parenthesis
type: behavior
versions: Python 3.7, Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com