Coverage for python/lsst/utils/get_caller_name.py: 83%

6 statements  

« prev     ^ index     » next       coverage.py v6.4.1, created at 2022-06-11 02:29 -0700

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. 

11 

12__all__ = ["get_caller_name"] 

13 

14from deprecated.sphinx import deprecated 

15 

16from .introspection import get_caller_name as caller_name 

17 

18 

19@deprecated( 

20 reason="get_caller_name has moved to `lsst.utils.introspection.get_caller_name`." 

21 " Will be removed in v26.", 

22 version="v24", 

23 category=FutureWarning, 

24) 

25def get_caller_name(skip: int = 2) -> str: 

26 """Get the name of the caller method. 

27 

28 Any item that cannot be determined (or is not relevant, e.g. a free 

29 function has no class) is silently omitted, along with an 

30 associated separator. 

31 

32 Parameters 

33 ---------- 

34 skip : `int` 

35 How many levels of stack to skip while getting caller name; 

36 1 means "who calls me", 2 means "who calls my caller", etc. 

37 

38 Returns 

39 ------- 

40 name : `str` 

41 Name of the caller as a string in the form ``module.class.method``. 

42 An empty string is returned if ``skip`` exceeds the stack height. 

43 """ 

44 # Offset the stack level to account for redirect and deprecated wrapper. 

45 return caller_name(stacklevel=skip + 2)