Another Python 3.5 FUNCTION_VAR bug

Fixes #94
This commit is contained in:
rocky
2017-04-09 06:54:32 -04:00
parent b4a6c3c319
commit 792df2a7a7
4 changed files with 37 additions and 8 deletions

View File

@@ -14,3 +14,14 @@ def __init__(self, defaults=None, dict_type=_default_dict,
# Python 3.6+ replaces CALL_FUNCTION_VAR_KW with CALL_FUNCTION_EX
def deferred(*columns, **kw):
return ColumnProperty(deferred=True, *columns, **kw)
# From sqlalchemy/sql/selectable.py
class GenerativeSelect():
def __init__(self,
ClauseList,
util,
order_by=None):
self._order_by_clause = ClauseList(
*util.to_list(order_by),
_literal_as_text=5)

View File

@@ -482,14 +482,17 @@ class Python3Parser(PythonParser):
token.type = self.call_fn_name(token)
uniq_param = args_kw + args_pos
if self.version == 3.5 and opname.startswith('CALL_FUNCTION_VAR_KW'):
if self.version == 3.5 and opname.startswith('CALL_FUNCTION_VAR'):
# Python 3.5 changes the stack position of where * args, the
# first LOAD_FAST, below are located.
# Python 3.6+ replaces CALL_FUNCTION_VAR_KW with CALL_FUNCTION_EX
rule = ('call_function ::= LOAD_GLOBAL LOAD_FAST ' +
if opname.endswith('KW'):
kw = 'LOAD_FAST '
else:
kw = ''
rule = ('call_function ::= expr expr ' +
('pos_arg ' * args_pos) +
('kwarg ' * args_kw) + 'LOAD_FAST '
+ token.type)
('kwarg ' * args_kw) + kw + token.type)
self.add_unique_rule(rule, token.type, uniq_param, customize)
rule = ('call_function ::= expr ' +

View File

@@ -1771,16 +1771,31 @@ class SourceWalker(GenericASTTraversal, object):
str = '%c(%C, '
p2 = (1, -2, ', ')
if op == 'CALL_FUNCTION_VAR':
str += '*%c)'
# Python 3.5 only puts optional args (the VAR part)
# lowest down the stack
if self.version == 3.5:
if str == '%c(%C, ':
str = '%c(*%C, %c)'
else:
str += '*%c)'
entry = (str, 0, p2, -2)
elif op == 'CALL_FUNCTION_KW':
str += '**%c)'
entry = (str, 0, p2, -2)
else:
elif op == 'CALL_FUNCTION_VAR_KW':
str += '*%c, **%c)'
if p2[2]: p2 = (1, -3, ', ')
entry = (str, 0, p2, -3, -2)
# Python 3.5 only puts optional args (the VAR part)
# lowest down the stack
if self.version == 3.5:
if p2[2]: p2 = (2, -2, ', ')
entry = (str, 0, p2, 1, -2)
else:
if p2[2]: p2 = (1, -3, ', ')
entry = (str, 0, p2, -3, -2)
pass
else:
assert False, "Unhandled CALL_FUNCTION %s" % op
TABLE_R[k] = entry
pass
# handled by n_mapexpr: