Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2ce27b2

Browse files
committed
fix argcount generation for arg lists containing tuple unpacks
this is sort of a hack
1 parent 65d4ea0 commit 2ce27b2

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

Lib/compiler/pyassem.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(self, args=(), name='?', filename='<?>',
5353
# XXX why is the default value for flags 3?
5454
self.insts = []
5555
# used by makeCodeObject
56-
self.argcount = len(args)
56+
self._getArgCount(args)
5757
self.code = ''
5858
self.consts = [docstring]
5959
self.filename = filename
@@ -67,6 +67,16 @@ def __init__(self, args=(), name='?', filename='<?>',
6767
self.last_addr = 0
6868
self.lnotab = ''
6969

70+
def _getArgCount(self, args):
71+
if args and args[0][0] == '.':
72+
for i in range(len(args)):
73+
if args[i][0] == '.':
74+
num = i
75+
self.argcount = num + 1
76+
else:
77+
self.argcount = len(args)
78+
79+
7080
def __repr__(self):
7181
return "<bytecode: %d instrs>" % len(self.insts)
7282

@@ -231,7 +241,8 @@ def _convertArg(self, op, arg):
231241
return arg
232242

233243
nameOps = ('STORE_NAME', 'IMPORT_NAME', 'IMPORT_FROM',
234-
'STORE_ATTR', 'LOAD_ATTR', 'LOAD_NAME', 'DELETE_NAME')
244+
'STORE_ATTR', 'LOAD_ATTR', 'LOAD_NAME', 'DELETE_NAME',
245+
'DELETE_ATTR')
235246
localOps = ('LOAD_FAST', 'STORE_FAST', 'DELETE_FAST')
236247
globalOps = ('LOAD_GLOBAL', 'STORE_GLOBAL', 'DELETE_GLOBAL')
237248

Tools/compiler/compiler/pyassem.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(self, args=(), name='?', filename='<?>',
5353
# XXX why is the default value for flags 3?
5454
self.insts = []
5555
# used by makeCodeObject
56-
self.argcount = len(args)
56+
self._getArgCount(args)
5757
self.code = ''
5858
self.consts = [docstring]
5959
self.filename = filename
@@ -67,6 +67,16 @@ def __init__(self, args=(), name='?', filename='<?>',
6767
self.last_addr = 0
6868
self.lnotab = ''
6969

70+
def _getArgCount(self, args):
71+
if args and args[0][0] == '.':
72+
for i in range(len(args)):
73+
if args[i][0] == '.':
74+
num = i
75+
self.argcount = num + 1
76+
else:
77+
self.argcount = len(args)
78+
79+
7080
def __repr__(self):
7181
return "<bytecode: %d instrs>" % len(self.insts)
7282

@@ -231,7 +241,8 @@ def _convertArg(self, op, arg):
231241
return arg
232242

233243
nameOps = ('STORE_NAME', 'IMPORT_NAME', 'IMPORT_FROM',
234-
'STORE_ATTR', 'LOAD_ATTR', 'LOAD_NAME', 'DELETE_NAME')
244+
'STORE_ATTR', 'LOAD_ATTR', 'LOAD_NAME', 'DELETE_NAME',
245+
'DELETE_ATTR')
235246
localOps = ('LOAD_FAST', 'STORE_FAST', 'DELETE_FAST')
236247
globalOps = ('LOAD_GLOBAL', 'STORE_GLOBAL', 'DELETE_GLOBAL')
237248

0 commit comments

Comments
 (0)