MCPcopy Index your code
hub / github.com/RustPython/RustPython / findCaller

Method findCaller

Lib/logging/__init__.py:1594–1626  ·  view source on GitHub ↗

Find the stack frame of the caller so that we can note the source file name, line number and function name.

(self, stack_info=False, stacklevel=1)

Source from the content-addressed store, hash-verified

1592 self._log(level, msg, args, **kwargs)
1593
1594 def findCaller(self, stack_info=False, stacklevel=1):
1595 """
1596 Find the stack frame of the caller so that we can note the source
1597 file name, line number and function name.
1598 """
1599 f = currentframe()
1600 #On some versions of IronPython, currentframe() returns None if
1601 #IronPython isn't run with -X:Frames.
1602 if f is None:
1603 return "(unknown file)", 0, "(unknown function)", None
1604 while stacklevel > 0:
1605 next_f = f.f_back
1606 if next_f is None:
1607 ## We've got options here.
1608 ## If we want to use the last (deepest) frame:
1609 break
1610 ## If we want to mimic the warnings module:
1611 #return ("sys", 1, "(unknown function)", None)
1612 ## If we want to be pedantic:
1613 #raise ValueError("call stack is not deep enough")
1614 f = next_f
1615 if not _is_internal_frame(f):
1616 stacklevel -= 1
1617 co = f.f_code
1618 sinfo = None
1619 if stack_info:
1620 with io.StringIO() as sio:
1621 sio.write("Stack (most recent call last):\n")
1622 traceback.print_stack(f, file=sio)
1623 sinfo = sio.getvalue()
1624 if sinfo[-1] == '\n':
1625 sinfo = sinfo[:-1]
1626 return co.co_filename, f.f_lineno, co.co_name, sinfo
1627
1628 def makeRecord(self, name, level, fn, lno, msg, args, exc_info,
1629 func=None, extra=None, sinfo=None):

Callers 2

_logMethod · 0.95

Calls 5

currentframeFunction · 0.70
_is_internal_frameFunction · 0.70
writeMethod · 0.45
print_stackMethod · 0.45
getvalueMethod · 0.45

Tested by 1