Coverage for python/lsst/utils/get_caller_name.py: 89%
7 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-25 09:27 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-25 09:27 +0000
1# This file is part of utils.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# Use of this source code is governed by a 3-clause BSD-style
10# license that can be found in the LICENSE file.
12from __future__ import annotations
14__all__ = ["get_caller_name"]
16from deprecated.sphinx import deprecated
18from .introspection import get_caller_name as caller_name
21@deprecated(
22 reason="get_caller_name has moved to `lsst.utils.introspection.get_caller_name`."
23 " Will be removed in v26.",
24 version="v24",
25 category=FutureWarning,
26)
27def get_caller_name(skip: int = 2) -> str:
28 """Get the name of the caller method.
30 Any item that cannot be determined (or is not relevant, e.g. a free
31 function has no class) is silently omitted, along with an
32 associated separator.
34 Parameters
35 ----------
36 skip : `int`
37 How many levels of stack to skip while getting caller name;
38 1 means "who calls me", 2 means "who calls my caller", etc.
40 Returns
41 -------
42 name : `str`
43 Name of the caller as a string in the form ``module.class.method``.
44 An empty string is returned if ``skip`` exceeds the stack height.
45 """
46 # Offset the stack level to account for redirect and deprecated wrapper.
47 return caller_name(stacklevel=skip + 2)