Skip to content

Commit 7e8f115

Browse files
author
rocky
committed
Revise for streamline method calls
1 parent 0e51725 commit 7e8f115

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

pytest/test_std.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def test_distb(traceback_fixture, stream_fixture):
155155
# assert actual == expected
156156

157157
def test_get_instructions():
158+
# opc = get_opcode_module(PYTHON_VERSION_TRIPLE, PYTHON_IMPLEMENTATION)
158159
actual = list(dis.get_instructions(TEST_SOURCE_CODE))
159160
actual_len = len(actual)
160161
assert actual_len > 0

xdis/bytecode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ def get_instructions(self, x):
814814
the disassembled code object.
815815
"""
816816
co = get_code_object(x)
817-
return get_instructions_bytes(co.co_code, self.opc)
817+
return get_instructions_bytes(co, self.opc)
818818

819819

820820
def list2bytecode(

xdis/std.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def disco(self, code, lasti=-1, file=None) -> None:
223223
python_implementation=self.python_version_tuple,
224224
)
225225

226-
def get_instructions(self, x, first_line=None):
226+
def get_instructions(self, x):
227227
"""Iterator for the opcodes in methods, functions or code
228228
229229
Generates a series of Instruction named tuples giving the details of
@@ -234,7 +234,11 @@ def get_instructions(self, x, first_line=None):
234234
Otherwise, the source line information (if any) is taken directly from
235235
the disassembled code object.
236236
"""
237-
return self.Bytecode(x).get_instructions(x, first_line)
237+
if isinstance(x, str):
238+
code_obj = compile(x, f"<std.py {str}>", "exec")
239+
else:
240+
code_obj = x
241+
return self.Bytecode(code_obj).get_instructions(code_obj)
238242

239243
def findlinestarts(self, code):
240244
"""Find the offsets in a byte code which are start of lines in the source.

0 commit comments

Comments
 (0)