summaryrefslogtreecommitdiffstats
path: root/Lib/dis.py
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2021-09-14 09:09:05 (GMT)
committerGitHub <noreply@github.com>2021-09-14 09:09:05 (GMT)
commitc99fc4e53a60084df88ac5c69b3b13bc033677e1 (patch)
treedec1308bd562dfd578ee29d15d0bb8ea5acb0ac2 /Lib/dis.py
parentc2f1e953371c25f6c42b599ba3d8797effbb503e (diff)
downloadcpython-c99fc4e53a60084df88ac5c69b3b13bc033677e1.zip
cpython-c99fc4e53a60084df88ac5c69b3b13bc033677e1.tar.gz
cpython-c99fc4e53a60084df88ac5c69b3b13bc033677e1.tar.bz2
bpo-45168: change dis output to omit missing values rather than replacing them by their index (GH-28313)
Diffstat (limited to 'Lib/dis.py')
-rw-r--r--Lib/dis.py25
1 files changed, 16 insertions, 9 deletions
diff --git a/Lib/dis.py b/Lib/dis.py
index a073572..b9f8658 100644
--- a/Lib/dis.py
+++ b/Lib/dis.py
@@ -125,6 +125,13 @@ def pretty_flags(flags):
names.append(hex(flags))
return ", ".join(names)
+class _Unknown:
+ def __repr__(self):
+ return "<unknown>"
+
+# Sentinel to represent values that cannot be calculated
+UNKNOWN = _Unknown()
+
def _get_code_object(x):
"""Helper to handle methods, compiled or raw code objects, and strings."""
# Extract functions from methods.
@@ -315,28 +322,28 @@ def _get_const_info(const_index, const_list):
Returns the dereferenced constant and its repr if the constant
list is defined.
- Otherwise returns the constant index and its repr().
+ Otherwise returns the sentinel value dis.UNKNOWN for the value
+ and an empty string for its repr.
"""
- argval = const_index
if const_list is not None:
argval = const_list[const_index]
- return argval, repr(argval)
+ return argval, repr(argval)
+ else:
+ return UNKNOWN, ''
def _get_name_info(name_index, get_name, **extrainfo):
"""Helper to get optional details about named references
Returns the dereferenced name as both value and repr if the name
list is defined.
- Otherwise returns the name index and its repr().
+ Otherwise returns the sentinel value dis.UNKNOWN for the value
+ and an empty string for its repr.
"""
- argval = name_index
if get_name is not None:
argval = get_name(name_index, **extrainfo)
- argrepr = argval
+ return argval, argval
else:
- argrepr = repr(argval)
- return argval, argrepr
-
+ return UNKNOWN, ''
def parse_varint(iterator):
b = next(iterator)