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

7 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-08 09:53 +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. 

11 

12from __future__ import annotations 

13 

14__all__ = ["get_caller_name"] 

15 

16from deprecated.sphinx import deprecated 

17 

18from .introspection import get_caller_name as caller_name 

19 

20 

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. 

29 

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. 

33 

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. 

39 

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)