@@ -44,9 +44,13 @@ def _try_compile(source: str, name: str) -> CodeType:
4444 return c
4545
4646
47- def code_info (x , version_tuple : Tuple [int , ...], python_implementation : PythonImplementation ) -> str :
47+ def code_info (
48+ x , version_tuple : Tuple [int , ...], python_implementation : PythonImplementation
49+ ) -> str :
4850 """Formatted details of methods, functions, or code."""
49- return format_code_info (get_code_object (x ), version_tuple , python_implementation = python_implementation )
51+ return format_code_info (
52+ get_code_object (x ), version_tuple , python_implementation = python_implementation
53+ )
5054
5155
5256def get_code_object (x ):
@@ -259,7 +263,12 @@ def op_has_argument(opcode: int, opc) -> bool:
259263 """
260264 Return True if `opcode` instruction has an operand.
261265 """
262- return opcode in opc .hasarg if hasattr (opc , "hasarg" ) else opcode >= opc .HAVE_ARGUMENT
266+ return (
267+ opcode in opc .hasarg
268+ if hasattr (opc , "hasarg" )
269+ and opc .python_implementation is PythonImplementation .RustPython
270+ else opcode >= opc .HAVE_ARGUMENT
271+ )
263272
264273
265274def pretty_flags (flags , python_implementation = PYTHON_IMPLEMENTATION ) -> str :
@@ -269,7 +278,10 @@ def pretty_flags(flags, python_implementation=PYTHON_IMPLEMENTATION) -> str:
269278 for i in range (32 ):
270279 flag = 1 << i
271280 if flags & flag :
272- if python_implementation == PythonImplementation .PyPy and flag in PYPY_COMPILER_FLAG_NAMES :
281+ if (
282+ python_implementation == PythonImplementation .PyPy
283+ and flag in PYPY_COMPILER_FLAG_NAMES
284+ ):
273285 names .append (PYPY_COMPILER_FLAG_NAMES .get (flag , hex (flag )))
274286 else :
275287 names .append (COMPILER_FLAG_NAMES .get (flag , hex (flag )))
@@ -320,7 +332,9 @@ def format_code_info(
320332 pass
321333
322334 if version_tuple >= (1 , 3 ):
323- lines .append ("# Flags: %s" % pretty_flags (co .co_flags , python_implementation ))
335+ lines .append (
336+ "# Flags: %s" % pretty_flags (co .co_flags , python_implementation )
337+ )
324338
325339 if version_tuple >= (1 , 5 ):
326340 lines .append ("# First Line: %s" % co .co_firstlineno )
@@ -373,7 +387,9 @@ def format_exception_table(bytecode, version_tuple) -> str:
373387 for entry in bytecode .exception_entries :
374388 lasti = " lasti" if entry .lasti else ""
375389 end = entry .end - 2
376- lines .append (f" { entry .start } to { end } -> { entry .target } [{ entry .depth } ]{ lasti } " )
390+ lines .append (
391+ f" { entry .start } to { end } -> { entry .target } [{ entry .depth } ]{ lasti } "
392+ )
377393 return "\n " .join (lines )
378394
379395
@@ -414,7 +430,11 @@ def unpack_opargs_bytecode(code, opc):
414430 offset += 1
415431 if op_has_argument (op , opc ):
416432 arg = code2num (code , offset ) | extended_arg
417- extended_arg = extended_arg_val (opc , arg ) if hasattr (opc , "EXTENDED_ARG" ) and op == opc .EXTENDED_ARG else 0
433+ extended_arg = (
434+ extended_arg_val (opc , arg )
435+ if hasattr (opc , "EXTENDED_ARG" ) and op == opc .EXTENDED_ARG
436+ else 0
437+ )
418438 offset += 2
419439 else :
420440 arg = None
@@ -474,7 +494,7 @@ def xstack_effect(opcode, opc, oparg: int = 0, jump=None):
474494 if opname == "BUILD_MAP" and version_tuple >= (3 , 5 ):
475495 return 1 - (2 * oparg )
476496 if opname in ("UNPACK_SEQUENCE" ,):
477- return oparg - 1
497+ return oparg - 1
478498 elif opname in ("UNPACK_EX" ):
479499 return (oparg & 0xFF ) + (oparg >> 8 )
480500 elif opname == "BUILD_INTERPOLATION" :
0 commit comments