Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e7789a6

Browse files
committed
Defer inspect.currentframe only used for debugging
1 parent 066706e commit e7789a6

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

CppHeaderParser/CppHeaderParser.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ def warning_print(fmt, *args):
100100

101101
if debug:
102102

103+
class _debug_caller_lineno:
104+
def __str__(self):
105+
return str(inspect.currentframe().f_back.f_back.f_back.f_lineno)
106+
107+
debug_caller_lineno = _debug_caller_lineno()
108+
103109
def debug_print(fmt, *args):
104110
fmt = "[%4d] " + fmt
105111
args = (inspect.currentframe().f_back.f_lineno,) + args
@@ -108,6 +114,8 @@ def debug_print(fmt, *args):
108114

109115
else:
110116

117+
debug_caller_lineno = None
118+
111119
def debug_print(fmt, *args):
112120
pass
113121

@@ -3237,10 +3245,10 @@ def _evaluate_stack(self, token=None):
32373245
nameStackCopy = self.nameStack[:]
32383246

32393247
debug_print(
3240-
"Evaluating stack %s\n BraceDepth: %s (called from %d)",
3248+
"Evaluating stack %s\n BraceDepth: %s (called from %s)",
32413249
self.nameStack,
32423250
self.braceDepth,
3243-
inspect.currentframe().f_back.f_lineno,
3251+
debug_caller_lineno,
32443252
)
32453253

32463254
# Handle special case of overloading operator ()

0 commit comments

Comments
 (0)