You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
3.6 CALL_FUNCTION_KW handling
This commit is contained in:
BIN
test/bytecode_3.6/04_class_kwargs.pyc
Normal file
BIN
test/bytecode_3.6/04_class_kwargs.pyc
Normal file
Binary file not shown.
11
test/simple_source/bug36/04_class_kwargs.py
Normal file
11
test/simple_source/bug36/04_class_kwargs.py
Normal file
@@ -0,0 +1,11 @@
|
||||
# From 3.6 test_abc.py
|
||||
# Bug was Reciever() class definition
|
||||
import abc
|
||||
import unittest
|
||||
class TestABCWithInitSubclass(unittest.TestCase):
|
||||
def test_works_with_init_subclass(self):
|
||||
class ReceivesClassKwargs:
|
||||
def __init_subclass__(cls, **kwargs):
|
||||
super().__init_subclass__()
|
||||
class Receiver(ReceivesClassKwargs, abc.ABC, x=1, y=2, z=3):
|
||||
pass
|
@@ -1664,39 +1664,58 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
def print_super_classes3(self, node):
|
||||
n = len(node)-1
|
||||
if node.kind != 'expr':
|
||||
assert node[n].kind.startswith('CALL_FUNCTION')
|
||||
|
||||
kwargs = None
|
||||
# 3.6+ starts having this
|
||||
if node[n].kind.startswith('CALL_FUNCTION_KW'):
|
||||
# 3.6+ starts does this
|
||||
kwargs = node[n-1].attr
|
||||
assert isinstance(kwargs, tuple)
|
||||
assert node[n].kind.startswith('CALL_FUNCTION')
|
||||
for i in range(n-2, 0, -1):
|
||||
if not node[i].kind in ['expr', 'LOAD_CLASSNAME']:
|
||||
break
|
||||
pass
|
||||
i = n - (len(kwargs)+1)
|
||||
j = 1 + n - node[n].attr
|
||||
else:
|
||||
for i in range(n-2, 0, -1):
|
||||
if not node[i].kind in ['expr', 'LOAD_CLASSNAME']:
|
||||
break
|
||||
pass
|
||||
|
||||
if i == n-2:
|
||||
return
|
||||
i += 2
|
||||
|
||||
if i == n-2:
|
||||
return
|
||||
line_separator = ', '
|
||||
sep = ''
|
||||
self.write('(')
|
||||
j = 0
|
||||
i += 2
|
||||
if kwargs:
|
||||
# Last arg is tuple of keyword values: omit
|
||||
l = n - 1
|
||||
else:
|
||||
l = n
|
||||
while i < l:
|
||||
# 3.6+ may have this
|
||||
if kwargs:
|
||||
self.write("%s=" % kwargs[j])
|
||||
|
||||
if kwargs:
|
||||
# 3.6+ does this
|
||||
while j < i:
|
||||
self.write(sep)
|
||||
value = self.traverse(node[j])
|
||||
self.write("%s" % value)
|
||||
sep = line_separator
|
||||
j += 1
|
||||
value = self.traverse(node[i])
|
||||
i += 1
|
||||
self.write(sep, value)
|
||||
sep = line_separator
|
||||
pass
|
||||
|
||||
j = 0
|
||||
while i < l:
|
||||
self.write(sep)
|
||||
value = self.traverse(node[i])
|
||||
self.write("%s=%s" % (kwargs[j], value))
|
||||
sep = line_separator
|
||||
j += 1
|
||||
i += 1
|
||||
else:
|
||||
while i < l:
|
||||
value = self.traverse(node[i])
|
||||
i += 1
|
||||
self.write(sep, value)
|
||||
sep = line_separator
|
||||
pass
|
||||
pass
|
||||
else:
|
||||
self.write('(')
|
||||
|
Reference in New Issue
Block a user