@@ -171,8 +171,8 @@ def parse_byte_and_args(self):
171
171
In Python3.6 the format is 2 bytes per instruction."""
172
172
f = self .frame
173
173
opoffset = f .f_lasti
174
- if f . py36_opcodes :
175
- currentOp = f .py36_opcodes [opoffset ]
174
+ if sys . version_info >= ( 3 , 6 ) :
175
+ currentOp = f .opcodes [opoffset ]
176
176
byteCode = currentOp .opcode
177
177
byteName = currentOp .opname
178
178
else :
@@ -181,7 +181,7 @@ def parse_byte_and_args(self):
181
181
f .f_lasti += 1
182
182
arg = None
183
183
arguments = []
184
- if f . py36_opcodes and byteCode == dis .EXTENDED_ARG :
184
+ if sys . version_info >= ( 3 , 6 ) and byteCode == dis .EXTENDED_ARG :
185
185
# Prefixes any opcode which has an argument too big to fit into the
186
186
# default two bytes. ext holds two additional bytes which, taken
187
187
# together with the subsequent opcode’s argument, comprise a
@@ -191,7 +191,7 @@ def parse_byte_and_args(self):
191
191
# Lib/dis.py:_unpack_opargs
192
192
return self .parse_byte_and_args ()
193
193
if byteCode >= dis .HAVE_ARGUMENT :
194
- if f . py36_opcodes :
194
+ if sys . version_info >= ( 3 , 6 ) :
195
195
intArg = currentOp .arg
196
196
else :
197
197
arg = f .f_code .co_code [f .f_lasti :f .f_lasti + 2 ]
@@ -208,12 +208,12 @@ def parse_byte_and_args(self):
208
208
elif byteCode in dis .hasname :
209
209
arg = f .f_code .co_names [intArg ]
210
210
elif byteCode in dis .hasjrel :
211
- if f . py36_opcodes :
211
+ if sys . version_info >= ( 3 , 6 ) :
212
212
arg = f .f_lasti + intArg // 2
213
213
else :
214
214
arg = f .f_lasti + intArg
215
215
elif byteCode in dis .hasjabs :
216
- if f . py36_opcodes :
216
+ if sys . version_info >= ( 3 , 6 ) :
217
217
arg = intArg // 2
218
218
else :
219
219
arg = intArg
@@ -598,30 +598,49 @@ def byte_BUILD_TUPLE_UNPACK_WITH_CALL(self, count):
598
598
# This is similar to BUILD_TUPLE_UNPACK, but is used for f(*x, *y, *z)
599
599
# call syntax. The stack item at position count + 1 should be the
600
600
# corresponding callable f.
601
- self .byte_BUILD_TUPLE_UNPACK (count )
602
-
601
+ self .build_container_flat (count , tuple )
603
602
604
603
def byte_BUILD_TUPLE_UNPACK (self , count ):
605
604
# Pops count iterables from the stack, joins them in a single tuple,
606
605
# and pushes the result. Implements iterable unpacking in
607
606
# tuple displays (*x, *y, *z).
608
- elts = self .popn (count )
609
- self .push (tuple (e for l in elts for e in l ))
607
+ self .build_container_flat (count , tuple )
610
608
611
609
def byte_BUILD_TUPLE (self , count ):
612
- elts = self .popn (count )
613
- self .push (tuple (elts ))
610
+ self .build_container (count , tuple )
614
611
615
612
def byte_BUILD_LIST_UNPACK (self , count ):
613
+ # This is similar to BUILD_TUPLE_UNPACK, but a list instead of tuple.
614
+ # Implements iterable unpacking in list displays [*x, *y, *z].
615
+ self .build_container_flat (count , list )
616
+
617
+ def byte_BUILD_SET_UNPACK (self , count ):
618
+ # This is similar to BUILD_TUPLE_UNPACK, but a set instead of tuple.
619
+ # Implements iterable unpacking in set displays {*x, *y, *z}.
620
+ self .build_container_flat (count , set )
621
+
622
+ def byte_BUILD_MAP_UNPACK (self , count ):
623
+ # Pops count mappings from the stack, merges them to a single dict,
624
+ # and pushes the result. Implements dictionary unpacking in dictionary
625
+ # displays {**x, **y, **z}.
626
+ self .build_container (count , dict )
627
+
628
+ def byte_BUILD_MAP_UNPACK_WITH_CALL (self , count ):
629
+ self .build_container (count , dict )
630
+
631
+ def build_container_flat (self , count , container_fn ) :
632
+ elts = self .popn (count )
633
+ self .push (container_fn (e for l in elts for e in l ))
634
+
635
+ def build_container (self , count , container_fn ) :
616
636
elts = self .popn (count )
617
- self .push ([ e for l in elts for e in l ] )
637
+ self .push (container_fn ( elts ) )
618
638
619
639
def byte_BUILD_LIST (self , count ):
620
640
elts = self .popn (count )
621
641
self .push (elts )
622
642
623
643
def byte_BUILD_SET (self , count ):
624
- # TODO: Not documented in Py2 docs.
625
644
elts = self .popn (count )
626
645
self .push (set (elts ))
627
646
@@ -636,7 +655,7 @@ def byte_BUILD_CONST_KEY_MAP(self, count):
636
655
637
656
def byte_BUILD_MAP (self , count ):
638
657
# Pushes a new dictionary on to stack.
639
- if sys .version_info [: 2 ] < (3 , 5 ):
658
+ if sys .version_info < (3 , 5 ):
640
659
self .push ({})
641
660
return
642
661
# Pop 2*count items so that
0 commit comments