Skip to content

Commit 74d6600

Browse files
committed
test: updated lab/show_pyc.py for latest code object stuff
1 parent 9c4528d commit 74d6600

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lab/show_pyc.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import sys
1717
import time
1818
import types
19+
import warnings
20+
1921

2022

2123
def show_pyc_file(fname):
@@ -85,6 +87,10 @@ def show_py_text(text, fname="<string>"):
8587
('CO_FUTURE_ANNOTATIONS', 0x1000000),
8688
]
8789

90+
if sys.version_info >= (3, 14):
91+
CO_FLAGS += [
92+
('CO_NO_MONITORING_EVENTS', 0x2000000),
93+
]
8894

8995
def show_code(code, indent='', number=None):
9096
label = ""
@@ -98,7 +104,12 @@ def show_code(code, indent='', number=None):
98104
print("%sstacksize %d" % (indent, code.co_stacksize))
99105
print(f"{indent}flags {code.co_flags:04x}: {flag_words(code.co_flags, CO_FLAGS)}")
100106
show_hex("code", code.co_code, indent=indent)
101-
dis.disassemble(code)
107+
kwargs = {}
108+
if sys.version_info >= (3, 13):
109+
kwargs["show_offsets"] = True
110+
if sys.version_info >= (3, 14):
111+
kwargs["show_positions"] = True
112+
dis.disassemble(code, **kwargs)
102113
print("%sconsts" % indent)
103114
for i, const in enumerate(code.co_consts):
104115
if type(const) == types.CodeType:
@@ -120,6 +131,11 @@ def show_code(code, indent='', number=None):
120131
indent,
121132
", ".join(f"{line!r}:{start!r}-{end!r}" for start, end, line in code.co_lines())
122133
))
134+
if hasattr(code, "co_branches"):
135+
print(" {}co_branches {}".format(
136+
indent,
137+
", ".join(f"{start!r}:{taken!r}/{nottaken!r}" for start, taken, nottaken in code.co_branches())
138+
))
123139

124140
def show_hex(label, h, indent):
125141
h = binascii.hexlify(h)
@@ -167,6 +183,7 @@ def show_file(fname):
167183
print("Odd file:", fname)
168184

169185
def main(args):
186+
warnings.filterwarnings("ignore", category=DeprecationWarning)
170187
if args[0] == '-c':
171188
show_py_text(" ".join(args[1:]).replace(";", "\n"))
172189
else:

0 commit comments

Comments
 (0)