1616import sys
1717import time
1818import types
19+ import warnings
20+
1921
2022
2123def 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
8995def 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
124140def show_hex (label , h , indent ):
125141 h = binascii .hexlify (h )
@@ -167,6 +183,7 @@ def show_file(fname):
167183 print ("Odd file:" , fname )
168184
169185def 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