You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 16:59:52 +08:00
differing ways to do "yield from" in 3.3-3.5
This commit is contained in:
BIN
test/bytecode_3.5/05_yield_from.pyc
Normal file
BIN
test/bytecode_3.5/05_yield_from.pyc
Normal file
Binary file not shown.
@@ -1,8 +1,11 @@
|
|||||||
# Python 3.3 and above only
|
# Python 3.3 and above only
|
||||||
# Tests
|
# Tests
|
||||||
|
|
||||||
|
# 3.3, 3.4
|
||||||
# yield_from ::= expr expr YIELD_FROM
|
# yield_from ::= expr expr YIELD_FROM
|
||||||
# expr ::= yield_from
|
# expr ::= yield_from
|
||||||
|
|
||||||
|
# 3.5:
|
||||||
|
|
||||||
def _walk_dir(dir, ddir=None):
|
def _walk_dir(dir, ddir=None):
|
||||||
yield from _walk_dir(dir, ddir=dfile)
|
yield from _walk_dir(dir, ddir=dfile)
|
||||||
|
@@ -56,9 +56,6 @@ class Python3Parser(PythonParser):
|
|||||||
sstmt ::= ifelsestmtr
|
sstmt ::= ifelsestmtr
|
||||||
sstmt ::= return_stmt RETURN_LAST
|
sstmt ::= return_stmt RETURN_LAST
|
||||||
|
|
||||||
stmts_opt ::= stmts
|
|
||||||
stmts_opt ::= passstmt
|
|
||||||
|
|
||||||
return_if_stmts ::= return_if_stmt come_from_opt
|
return_if_stmts ::= return_if_stmt come_from_opt
|
||||||
return_if_stmts ::= _stmts return_if_stmt
|
return_if_stmts ::= _stmts return_if_stmt
|
||||||
return_if_stmt ::= ret_expr RETURN_END_IF
|
return_if_stmt ::= ret_expr RETURN_END_IF
|
||||||
@@ -198,6 +195,8 @@ class Python3Parser(PythonParser):
|
|||||||
except_stmt ::= except_cond2 except_suite
|
except_stmt ::= except_cond2 except_suite
|
||||||
except_stmt ::= except_cond2 except_suite_finalize
|
except_stmt ::= except_cond2 except_suite_finalize
|
||||||
except_stmt ::= except
|
except_stmt ::= except
|
||||||
|
|
||||||
|
## FIXME: what's except_pop_except?
|
||||||
except_stmt ::= except_pop_except
|
except_stmt ::= except_pop_except
|
||||||
|
|
||||||
# Python3 introduced POP_EXCEPT
|
# Python3 introduced POP_EXCEPT
|
||||||
@@ -284,10 +283,6 @@ class Python3Parser(PythonParser):
|
|||||||
|
|
||||||
# Python3 drops slice0..slice3
|
# Python3 drops slice0..slice3
|
||||||
|
|
||||||
# Python 3.3+ adds yield from
|
|
||||||
expr ::= yield_from
|
|
||||||
yield_from ::= expr expr YIELD_FROM
|
|
||||||
|
|
||||||
# In Python 2, DUP_TOP_TWO is DUP_TOPX_2
|
# In Python 2, DUP_TOP_TWO is DUP_TOPX_2
|
||||||
binary_subscr2 ::= expr expr DUP_TOP_TWO BINARY_SUBSCR
|
binary_subscr2 ::= expr expr DUP_TOP_TWO BINARY_SUBSCR
|
||||||
'''
|
'''
|
||||||
@@ -563,12 +558,22 @@ class Python33Parser(Python3Parser):
|
|||||||
"""
|
"""
|
||||||
# Store locals is only in Python 3.2 and 3.3
|
# Store locals is only in Python 3.2 and 3.3
|
||||||
designator ::= STORE_LOCALS
|
designator ::= STORE_LOCALS
|
||||||
|
|
||||||
|
# Python 3.3 adds yield from.
|
||||||
|
expr ::= yield_from
|
||||||
|
yield_from ::= expr expr YIELD_FROM
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Python34Parser(Python3Parser):
|
class Python34Parser(Python3Parser):
|
||||||
def p_34(self, args):
|
def p_34(self, args):
|
||||||
"""
|
"""
|
||||||
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD _come_from
|
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD _come_from
|
||||||
|
|
||||||
|
# Python 3.3 added yield from. Do it the same way as in
|
||||||
|
# 3.3
|
||||||
|
|
||||||
|
expr ::= yield_from
|
||||||
|
yield_from ::= expr expr YIELD_FROM
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Python35onParser(Python3Parser):
|
class Python35onParser(Python3Parser):
|
||||||
@@ -576,7 +581,7 @@ class Python35onParser(Python3Parser):
|
|||||||
"""
|
"""
|
||||||
# Python 3.5+ has WITH_CLEANUP_START/FINISH
|
# Python 3.5+ has WITH_CLEANUP_START/FINISH
|
||||||
|
|
||||||
withstmt ::= expr SETUP_WITH with_setup suite_stmts_opt
|
withstmt ::= expr SETUP_WITH exprlist suite_stmts_opt
|
||||||
POP_BLOCK LOAD_CONST COME_FROM
|
POP_BLOCK LOAD_CONST COME_FROM
|
||||||
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
||||||
|
|
||||||
@@ -585,8 +590,10 @@ class Python35onParser(Python3Parser):
|
|||||||
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
||||||
|
|
||||||
|
|
||||||
# Python 3.5+ also has yeild from
|
# Python 3.3+ also has yield from. 3.5 does it
|
||||||
|
# differently than 3.3, 3.4
|
||||||
|
|
||||||
|
expr ::= yield_from
|
||||||
yield_from ::= expr GET_YIELD_FROM_ITER LOAD_CONST YIELD_FROM
|
yield_from ::= expr GET_YIELD_FROM_ITER LOAD_CONST YIELD_FROM
|
||||||
|
|
||||||
# Python 3.5 has more loop optimization that removes
|
# Python 3.5 has more loop optimization that removes
|
||||||
@@ -614,7 +621,24 @@ class Python34ParserSingle(Python34Parser, PythonParserSingle):
|
|||||||
class Python35onParserSingle(Python35onParser, PythonParserSingle):
|
class Python35onParserSingle(Python35onParser, PythonParserSingle):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if __name__ == '__main__':
|
def info(args):
|
||||||
# Check grammar
|
# Check grammar
|
||||||
|
# Should also add a way to dump grammar
|
||||||
|
import sys
|
||||||
p = Python3Parser()
|
p = Python3Parser()
|
||||||
|
if len(args) > 0:
|
||||||
|
arg = args[0]
|
||||||
|
if arg == '3.5':
|
||||||
|
p = Python35onParser()
|
||||||
|
elif arg == '3.4':
|
||||||
|
p = Python34Parser()
|
||||||
|
elif arg == '3.3':
|
||||||
|
p = Python33Parser()
|
||||||
|
elif arg == '3.2':
|
||||||
|
p = Python32Parser()
|
||||||
p.checkGrammar()
|
p.checkGrammar()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import sys
|
||||||
|
info(sys.argv)
|
||||||
|
@@ -726,7 +726,12 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
def n_yield_from(self, node):
|
def n_yield_from(self, node):
|
||||||
self.write('yield from')
|
self.write('yield from')
|
||||||
self.write(' ')
|
self.write(' ')
|
||||||
self.preorder(node[0])
|
if 3.3 <= self.version <= 3.4:
|
||||||
|
self.preorder(node[0][0][0][0])
|
||||||
|
elif self.version >= 3.5:
|
||||||
|
self.preorder(node[0])
|
||||||
|
else:
|
||||||
|
assert False, "dunno about this python version"
|
||||||
self.prune() # stop recursing
|
self.prune() # stop recursing
|
||||||
|
|
||||||
def n_buildslice3(self, node):
|
def n_buildslice3(self, node):
|
||||||
|
Reference in New Issue
Block a user