[issue38871] lib2to3 generates invalid code with filter and ternary operator

2020-01-07 Thread miss-islington


miss-islington  added the comment:


New changeset 39a5c889d30d03a88102e56f03ee0c95db198fb3 by Miss Islington (bot) 
in branch '3.8':
bpo-38871: Fix lib2to3 for filter-based statements that contain lambda 
(GH-17780)
https://github.com/python/cpython/commit/39a5c889d30d03a88102e56f03ee0c95db198fb3


--

___
Python tracker 

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



[issue38871] lib2to3 generates invalid code with filter and ternary operator

2020-01-07 Thread miss-islington


miss-islington  added the comment:


New changeset 535a3c4e3da2f0076bd62f04fb2cc44999fc2419 by Miss Islington (bot) 
in branch '3.7':
bpo-38871: Fix lib2to3 for filter-based statements that contain lambda 
(GH-17780)
https://github.com/python/cpython/commit/535a3c4e3da2f0076bd62f04fb2cc44999fc2419


--
nosy: +miss-islington

___
Python tracker 

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



[issue38871] lib2to3 generates invalid code with filter and ternary operator

2020-01-07 Thread STINNER Victor


STINNER Victor  added the comment:

Thanks Zoran Simic to the bug report, and thanks Dong-hee Na for fixing it.

It's fixed in the master branch and backports to 3.7 and 3.8 will land as soon 
as the CI tests pass.

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
versions: +Python 3.9

___
Python tracker 

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



[issue38871] lib2to3 generates invalid code with filter and ternary operator

2020-01-07 Thread miss-islington


Change by miss-islington :


--
pull_requests: +17310
pull_request: https://github.com/python/cpython/pull/17900

___
Python tracker 

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



[issue38871] lib2to3 generates invalid code with filter and ternary operator

2020-01-07 Thread miss-islington


Change by miss-islington :


--
pull_requests: +17309
pull_request: https://github.com/python/cpython/pull/17899

___
Python tracker 

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



[issue38871] lib2to3 generates invalid code with filter and ternary operator

2020-01-07 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset b821173b5458d137c8d5edb6e9b4997aac800a38 by Victor Stinner 
(Dong-hee Na) in branch 'master':
bpo-38871: Fix lib2to3 for filter-based statements that contain lambda 
(GH-17780)
https://github.com/python/cpython/commit/b821173b5458d137c8d5edb6e9b4997aac800a38


--
nosy: +vstinner

___
Python tracker 

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



[issue38871] lib2to3 generates invalid code with filter and ternary operator

2020-01-01 Thread Dong-hee Na


Change by Dong-hee Na :


--
keywords: +patch
pull_requests: +17213
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/17780

___
Python tracker 

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



[issue38871] lib2to3 generates invalid code with filter and ternary operator

2019-11-23 Thread Dong-hee Na


Dong-hee Na  added the comment:

Dear core developers,

I 'd like to discuss fixing this issue.
IMHO, There are 2 options to fix this issue.

1. Add parenthesize when creating ListComp.
The change will be as follow:
 new = ListComp(results.get("fp").clone(),
results.get("fp").clone(),
results.get("it").clone(),
-   results.get("xp").clone())
+   parenthesize(results.get("xp").clone()))

But generated codes are not pretty.

2. Transform the lambda function as same as a normal function.
The only needed is removing lambda specific logics on fixer.

The generated code will be like this in this case.
x = filter(lambda x: True if x > 2 else False, data)
x = list(filter(lambda x: True if x > 2 else False, data))

Personally, I prefer the 2nd option because it's more clear.
If the proposal is accepted, I 'd like to fix this issue. 

If there are any ideas, please let me know.
Thank you always!

--
nosy: +benjamin.peterson

___
Python tracker 

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



[issue38871] lib2to3 generates invalid code with filter and ternary operator

2019-11-20 Thread Dong-hee Na


Dong-hee Na  added the comment:

I can reproduce on the latest master branch.

./python Tools/scripts/2to3 2.py
RefactoringTool: Skipping optional fixer: buffer
RefactoringTool: Skipping optional fixer: idioms
RefactoringTool: Skipping optional fixer: set_literal
RefactoringTool: Skipping optional fixer: ws_comma
RefactoringTool: Refactored 2.py
--- 2.py(original)
+++ 2.py(refactored)
@@ -1,3 +1,3 @@
 data = [1, 2, 3, 4, 5]
-x = filter(lambda x: True if x > 2 else False, data)
+x = [x for x in data if True if x > 2 else False]
 print(x)
RefactoringTool: Files that need to be modified:
RefactoringTool: 2.py

--
nosy: +corona10

___
Python tracker 

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



[issue38871] lib2to3 generates invalid code with filter and ternary operator

2019-11-20 Thread Zoran Simic


New submission from Zoran Simic :

This code snippet exposes a small edge case in lib2to3, where syntactically 
invalid code is generated:

data = [1, 2, 3, 4, 5]
x = filter(lambda x: True if x > 2 else False, data)
print(x)


lib2to3 transforms 2nd line above to:
x = [x for x in data if True if x > 2 else False]


which is invalid (would be OK with parentheses after 1st 'if')

Admittedly, the original code here is more complex that it should be ('True if 
foo else False' being equivalent to just 'foo'), but walked into this in "the 
real world" and wanted to report it.

--
components: 2to3 (2.x to 3.x conversion tool)
messages: 357112
nosy: Zoran Simic
priority: normal
severity: normal
status: open
title: lib2to3 generates invalid code with filter and ternary operator
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