You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Fix bug in 3x list comprehensions with ifnot
This commit is contained in:
Binary file not shown.
5
test/simple_source/comprehension/06_list_ifnot.py
Normal file
5
test/simple_source/comprehension/06_list_ifnot.py
Normal file
@@ -0,0 +1,5 @@
|
||||
# Test semantic handling of
|
||||
# [x for x in names2 if not y]
|
||||
# Bug seen in Python 3
|
||||
names2 = []
|
||||
names = [x for x in names2 if not len(x)]
|
@@ -1,17 +0,0 @@
|
||||
# Test semantic handling of
|
||||
# [x for x in names if not y]
|
||||
import os
|
||||
|
||||
def bug(dirname, pattern):
|
||||
if not dirname:
|
||||
if isinstance(pattern, bytes):
|
||||
dirname = bytes(os.curdir, 'ASCII')
|
||||
else:
|
||||
dirname = os.curdir
|
||||
try:
|
||||
names = os.listdir(dirname)
|
||||
except os.error:
|
||||
return []
|
||||
if not _ishidden(pattern):
|
||||
names = [x for x in names if not _ishidden(x)]
|
||||
return fnmatch.filter(names, pattern)
|
@@ -975,7 +975,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
self.prec = 27
|
||||
n = node[-1]
|
||||
assert n == 'list_iter'
|
||||
# find innerst node
|
||||
# find innermost node
|
||||
while n == 'list_iter':
|
||||
n = n[0] # recurse one step
|
||||
if n == 'list_for': n = n[3]
|
||||
@@ -1059,31 +1059,38 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
self.customize(code._customize)
|
||||
ast = ast[0][0][0][0][0]
|
||||
|
||||
try:
|
||||
n = ast[iter_index]
|
||||
except:
|
||||
from trepan.api import debug; debug()
|
||||
assert n == 'list_iter'
|
||||
|
||||
## FIXME: I'm not totally sure this is right.
|
||||
|
||||
# find innermost node
|
||||
designator = None
|
||||
list_if_node = None
|
||||
while n == 'list_iter':
|
||||
n = n[0] # recurse one step
|
||||
if n == 'list_for':
|
||||
if n[2] == 'designator':
|
||||
designator = n[2]
|
||||
n = n[3]
|
||||
elif n in ['list_if', 'list_if_not']:
|
||||
# FIXME: just a guess
|
||||
list_if_node = n[0]
|
||||
if n[1] == 'designator':
|
||||
designator = n[1]
|
||||
n = n[2]
|
||||
pass
|
||||
pass
|
||||
assert n == 'lc_body', ast
|
||||
assert designator, "Couldn't find designator in list comprehension"
|
||||
|
||||
self.preorder(n[0])
|
||||
self.write(' for ')
|
||||
self.preorder(designator)
|
||||
self.write(' in ')
|
||||
self.preorder(node[-3])
|
||||
if list_if_node:
|
||||
self.write(' if ')
|
||||
self.preorder(list_if_node)
|
||||
self.prec = p
|
||||
|
||||
def listcomprehension_walk2(self, node):
|
||||
|
Reference in New Issue
Block a user