@@ -170,7 +170,7 @@ class Instruction(NamedTuple):
170170 argval : Any
171171
172172 # String representation of argval if argval is not None.
173- argrepr : str
173+ argrepr : Optional [ str ]
174174
175175 # Offset of the instruction
176176 offset : int
@@ -293,7 +293,7 @@ def disassemble(
293293 hex_bytecode += " %02x" % (self .arg % 256 )
294294 else :
295295 hex_bytecode += " 00"
296- elif self .inst_size == 3 :
296+ elif self .inst_size == 3 and self . arg is not None :
297297 # Not 3.6 or later
298298 hex_bytecode += " %02x %02x" % divmod (self .arg , 256 )
299299
@@ -310,23 +310,31 @@ def disassemble(
310310 # for "asm" format, want additional explicit information
311311 # linking operands to tables.
312312 if asm_format == "asm" :
313- if self .is_jump ():
313+ if self .is_jump () and self . argrepr is not None :
314314 assert self .argrepr .startswith ("to " )
315315 jump_target = self .argrepr [len ("to " ) :]
316316 fields .append ("L" + jump_target )
317317 elif self .optype in indexed_operand :
318318 fields .append (repr (self .arg ))
319319 fields .append ("(%s)" % argrepr )
320320 argrepr = None
321- elif self .optype == "const" and not re .search (r"\s" , argrepr ):
321+ elif (
322+ self .optype == "const"
323+ and argrepr is not None
324+ and not re .search (r"\s" , argrepr )
325+ ):
322326 fields .append (repr (self .arg ))
323327 fields .append ("(%s)" % argrepr )
324328 argrepr = None
325329 else :
326330 fields .append (repr (self .arg ))
327331 elif asm_format in ("extended" , "extended-bytes" ):
328332 op = self .opcode
329- if self .is_jump () and line_starts .get (self .argval ) is not None :
333+ if (
334+ self .is_jump ()
335+ and line_starts is not None
336+ and line_starts .get (self .argval ) is not None
337+ ):
330338 new_instruction = list (self )
331339 new_instruction [- 2 ] = f"To line { line_starts [self .argval ]} "
332340 self = Instruction (* new_instruction )
@@ -381,7 +389,7 @@ def disassemble(
381389 prefix += "TOS = "
382390 fields .append (f"{ prefix } { self .tos_str } " )
383391 pass
384- else :
392+ elif self . argrepr is not None :
385393 fields .append (self .argrepr )
386394 pass
387395 pass
@@ -408,7 +416,7 @@ def disassemble(
408416 pass
409417 elif (
410418 hasattr (opc , "opcode_arg_fmt" ) and opc .opname [op ] in opc .opcode_arg_fmt
411- ):
419+ ) and self . argrepr is not None :
412420 fields .append (self .argrepr )
413421 pass
414422 pass
0 commit comments