Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions graalpython/com.oracle.graal.python.test/src/tests/test_dis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright (c) 2026, 2026, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The Universal Permissive License (UPL), Version 1.0
#
# Subject to the condition set forth below, permission is hereby granted to any
# person obtaining a copy of this software, associated documentation and/or
# data (collectively the "Software"), free of charge and under any and all
# copyright rights in the Software, and any and all patent rights owned or
# freely licensable by each licensor hereunder covering either (i) the
# unmodified Software as contributed to or provided by such licensor, or (ii)
# the Larger Works (as defined below), to deal in both
#
# (a) the Software, and
#
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
# one is included with the Software each a "Larger Work" to which the Software
# is contributed by such licensors),
#
# without restriction, including without limitation the rights to copy, create
# derivative works of, display, perform, and distribute the Software and make,
# use, sell, offer for sale, import, export, have made, and have sold the
# Software and the Larger Work(s), and to sublicense the foregoing rights on
# either these or other terms.
#
# This license is subject to the following condition:
#
# The above copyright notice and either this complete permission notice or at a
# minimum a reference to the UPL must be included in all copies or substantial
# portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import dis


def bytecode_target(value):
return value + 1


def test_bytecode_iteration_does_not_fail():
for _ in dis.Bytecode(bytecode_target):
pass
9 changes: 5 additions & 4 deletions graalpython/lib-python/3/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,6 @@ class Bytecode:
Iterating over this yields the bytecode operations as Instruction instances.
"""
def __init__(self, x, *, first_line=None, current_offset=None, show_caches=False, adaptive=False):
# GraalPy change
raise NotImplementedError("'dis' module is not supported on GraalPy")
self.codeobj = co = _get_code_object(x)
if first_line is None:
self.first_line = co.co_firstlineno
Expand All @@ -746,14 +744,15 @@ def __init__(self, x, *, first_line=None, current_offset=None, show_caches=False
self._linestarts = dict(findlinestarts(co))
self._original_object = x
self.current_offset = current_offset
self.exception_entries = _parse_exception_table(co)
# GraalPy change:
self.exception_entries = []
self.show_caches = show_caches
self.adaptive = adaptive

def __iter__(self):
co = self.codeobj
return _get_instructions_bytes(_get_code_array(co, self.adaptive),
co._varname_from_oparg,
None, # GraalPy change: replaced co._varname_from_oparg
co.co_names, co.co_consts,
self._linestarts,
line_offset=self._line_offset,
Expand All @@ -780,6 +779,8 @@ def info(self):

def dis(self):
"""Return a formatted view of the bytecode operations."""
# GraalPy change:
raise NotImplementedError("'dis' module is not supported on GraalPy")
co = self.codeobj
if self.current_offset is not None:
offset = self.current_offset
Expand Down
Loading