Keep pre-3.6 listcomp code patterns in 3.6

This commit is contained in:
rocky
2018-02-28 16:22:33 -05:00
parent b128e4fde6
commit 1fe432585e
4 changed files with 16 additions and 7 deletions

View File

@@ -16,3 +16,9 @@ def __init__(self, path, name, files=(), dirs=(), volumes=()):
for filename in files
for drive in volumes]
return f, f2
# From 3.6 codeop. The below listcomp is generated still
# like it was in 3.5
import __future__
_features = [getattr(__future__, fname)
for fname in __future__.all_feature_names]

View File

@@ -885,13 +885,15 @@ class Python3Parser(PythonParser):
"GET_ITER CALL_FUNCTION_1" % ('pos_arg '* args_pos, opname))
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
if is_pypy or (i >= 2 and tokens[i-2] == 'LOAD_LISTCOMP'):
if self.version < 3.6:
rule_pat = ("listcomp ::= %sLOAD_LISTCOMP %%s%s expr "
"GET_ITER CALL_FUNCTION_1" % ('expr ' * args_pos, opname))
else:
# 3.6+ bundles all of the 'exprs' in the rule above into a tuple.
rule_pat = ("listcomp ::= load_closure LOAD_LISTCOMP %%s%s expr "
"GET_ITER CALL_FUNCTION_1" % (opname,))
if self.version >= 3.6:
# 3.6+ sometimes bundles all of the
# 'exprs' in the rule above into a
# tuple.
rule_pat = ("listcomp ::= load_closure LOAD_LISTCOMP %%s%s "
"expr GET_ITER CALL_FUNCTION_1" % (opname,))
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
rule_pat = ("listcomp ::= %sLOAD_LISTCOMP %%s%s expr "
"GET_ITER CALL_FUNCTION_1" % ('expr ' * args_pos, opname))
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
if is_pypy or (i >= 2 and tokens[i-2] == 'LOAD_LAMBDA'):

View File

@@ -1697,6 +1697,7 @@ class SourceWalker(GenericASTTraversal, object):
assert n == 'lc_body', ast
# FIXME: add indentation around "for"'s and "in"'s
self.preorder(n[0])
if self.version < 3.6:
self.write(' for ')