16
16
import sys
17
17
import time
18
18
import types
19
+ import warnings
20
+
19
21
20
22
21
23
def show_pyc_file (fname ):
@@ -85,6 +87,10 @@ def show_py_text(text, fname="<string>"):
85
87
('CO_FUTURE_ANNOTATIONS' , 0x1000000 ),
86
88
]
87
89
90
+ if sys .version_info >= (3 , 14 ):
91
+ CO_FLAGS += [
92
+ ('CO_NO_MONITORING_EVENTS' , 0x2000000 ),
93
+ ]
88
94
89
95
def show_code (code , indent = '' , number = None ):
90
96
label = ""
@@ -98,7 +104,12 @@ def show_code(code, indent='', number=None):
98
104
print ("%sstacksize %d" % (indent , code .co_stacksize ))
99
105
print (f"{ indent } flags { code .co_flags :04x} : { flag_words (code .co_flags , CO_FLAGS )} " )
100
106
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 )
102
113
print ("%sconsts" % indent )
103
114
for i , const in enumerate (code .co_consts ):
104
115
if type (const ) == types .CodeType :
@@ -120,6 +131,11 @@ def show_code(code, indent='', number=None):
120
131
indent ,
121
132
", " .join (f"{ line !r} :{ start !r} -{ end !r} " for start , end , line in code .co_lines ())
122
133
))
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
+ ))
123
139
124
140
def show_hex (label , h , indent ):
125
141
h = binascii .hexlify (h )
@@ -167,6 +183,7 @@ def show_file(fname):
167
183
print ("Odd file:" , fname )
168
184
169
185
def main (args ):
186
+ warnings .filterwarnings ("ignore" , category = DeprecationWarning )
170
187
if args [0 ] == '-c' :
171
188
show_py_text (" " .join (args [1 :]).replace (";" , "\n " ))
172
189
else :
0 commit comments