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

Skip to content
Prev Previous commit
Next Next commit
Improve docstrings
  • Loading branch information
tomasr8 committed May 25, 2023
commit d0eaef74df2ba0e5e83eebff56b80cb96758b343
30 changes: 18 additions & 12 deletions Lib/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,9 @@ def show_code(co, *, file=None):
_OPARG_WIDTH = 5

def _get_jump_target(op, arg, offset):
"""Gets the bytecode offset of the jump target if this is a jump instruction,
otherwise returns None
"""Gets the bytecode offset of the jump target if this is a jump instruction.

Otherwise return None.
"""
deop = _deoptop(op)
caches = _inline_cache_entries[deop]
Expand All @@ -306,7 +307,7 @@ def _get_jump_target(op, arg, offset):
return target

class Instruction(_Instruction):
"""Details for a bytecode operation
"""Details for a bytecode operation.

Defined fields:
opname - human readable name for operation
Expand All @@ -325,40 +326,45 @@ class Instruction(_Instruction):

@property
def oparg(self):
"""Alias for Instruction.arg"""
"""Alias for Instruction.arg."""
return self.arg

@property
def baseopcode(self):
"""numeric code for the base operation if operation is specialized.
Otherwise equal to Instruction.opcode
"""Numeric code for the base operation if operation is specialized.

Otherwise equal to Instruction.opcode.
"""
return _deoptop(self.opcode)

@property
def baseopname(self):
"""human readable name for the base operation if operation is specialized.
Otherwise equal to Instruction.opname
"""Human readable name for the base operation if operation is specialized.

Otherwise equal to Instruction.opname.
"""
return opname[self.baseopcode]

@property
def cache_offset(self):
"""start index of the cache entries following the operation"""
"""Start index of the cache entries following the operation."""
return self.offset + 2

@property
def end_offset(self):
"""end index of the cache entries following the operation"""
"""End index of the cache entries following the operation."""
return self.cache_offset + _inline_cache_entries[self.opcode]*2

@property
def jump_target(self):
"""bytecode index of the jump target if this is a jump operation, otherwise None"""
"""Bytecode index of the jump target if this is a jump operation.

Otherwise return None.
"""
return _get_jump_target(self.opcode, self.arg, self.offset)

def _disassemble(self, lineno_width=3, mark_as_current=False, offset_width=4):
"""Format instruction details for inclusion in disassembly output
"""Format instruction details for inclusion in disassembly output.

*lineno_width* sets the width of the line number field (0 omits it)
*mark_as_current* inserts a '-->' marker arrow as part of the line
Expand Down