1
1
# -*- coding: utf-8 -*-
2
2
3
3
# Copyright (C) 2008-2010, 2013, 2015, 2017-2018, 2020-2021,
4
- # 2023-2024 Rocky Bernstein <[email protected] >
4
+ # 2023-2025 Rocky Bernstein <[email protected] >
5
5
#
6
6
# This program is free software: you can redistribute it and/or modify
7
7
# it under the terms of the GNU General Public License as published by
25
25
import re
26
26
from opcode import opname
27
27
from reprlib import repr
28
+ from types import FrameType
28
29
from typing import Optional , Tuple
29
30
30
31
import xdis
@@ -55,20 +56,25 @@ def deparse_fn(code):
55
56
have_deparser = True
56
57
except ImportError :
57
58
58
- def deparse_offset (code , name : str , list_i : int , _ ) -> tuple :
59
+ def deparse_offset (_code , _name : str , _list_i : int , _ ) -> tuple :
59
60
return None , None
60
61
61
62
have_deparser = False
62
63
63
64
_with_local_varname = re .compile (r"_\[[0-9+]]" )
64
65
65
66
66
- def count_frames (frame , count_start = 0 ):
67
+ def count_frames (frame : FrameType , count_start = 0 ):
67
68
"""Return a count of the number of frames"""
68
69
count = - count_start
69
- while frame :
70
- count += 1
71
- frame = frame .f_back
70
+ for _ in range (1000 ):
71
+ if frame is None :
72
+ break
73
+ else :
74
+ count += 1
75
+ frame = frame .f_back
76
+ else :
77
+ return 1000
72
78
return count
73
79
74
80
@@ -119,7 +125,7 @@ def deparse_source_from_code(code):
119
125
return source_text
120
126
121
127
122
- def format_function_name (frame , style : str ) -> Tuple [Optional [str ], Optional [str ]]:
128
+ def format_function_name (frame : FrameType , style : str ) -> Tuple [Optional [str ], Optional [str ]]:
123
129
"""
124
130
Pick out the function name from ``frame`` and return both the name
125
131
and the name styled according to ``style``
@@ -139,7 +145,7 @@ def format_function_name(frame, style: str) -> Tuple[Optional[str], Optional[str
139
145
return funcname , format_token (Function , funcname , style = style )
140
146
141
147
142
- def format_function_and_parameters (frame , debugger , style : str ) -> Tuple [bool , str ]:
148
+ def format_function_and_parameters (frame : FrameType , debugger , style : str ) -> Tuple [bool , str ]:
143
149
""" """
144
150
145
151
funcname , s = format_function_name (frame , style )
@@ -279,16 +285,18 @@ def frame2filesize(frame):
279
285
bc_path = None
280
286
path = frame .f_globals ["__file__" ]
281
287
source_path = getsourcefile (path )
288
+ if source_path is None :
289
+ return None , None
282
290
fs_size = os .stat (source_path ).st_size
283
291
if bc_path :
284
292
(
285
- version ,
286
- timestamp ,
287
- magic_int ,
288
- co ,
289
- is_pypy ,
293
+ _version ,
294
+ _timestamp ,
295
+ _magic_int ,
296
+ _co ,
297
+ _is_pypy ,
290
298
bc_source_size ,
291
- sip_hash ,
299
+ _sip_hash ,
292
300
) = xdis .load_module (bc_path , fast_load = True , get_code = False )
293
301
return fs_size , bc_source_size
294
302
elif osp .exists (path ):
0 commit comments