|
33 | 33 | import sys |
34 | 34 | import traceback |
35 | 35 | from types import FrameType |
36 | | -from typing import Any, Callable, List, Optional |
| 36 | +from typing import Any, Callable, List, Optional, TYPE_CHECKING |
37 | 37 |
|
38 | 38 | from cardinal_pythonlib.logs import get_brace_style_log_with_null_handler |
39 | 39 |
|
| 40 | +if TYPE_CHECKING: |
| 41 | + # noinspection PyUnresolvedReferences |
| 42 | + from inspect import FrameInfo |
| 43 | + |
40 | 44 | log = get_brace_style_log_with_null_handler(__name__) |
41 | 45 |
|
42 | 46 |
|
@@ -80,7 +84,7 @@ def get_class_name_from_frame(fr: FrameType) -> Optional[str]: |
80 | 84 | If the call was to a member function of a class, this function attempts |
81 | 85 | to read the class's name. It returns ``None`` otherwise. |
82 | 86 | """ |
83 | | - # https://stackoverflow.com/questions/2203424/python-how-to-retrieve-class-information-from-a-frame-object # noqa |
| 87 | + # https://stackoverflow.com/questions/2203424/python-how-to-retrieve-class-information-from-a-frame-object # noqa: E501 |
84 | 88 | args, _, _, value_dict = inspect.getargvalues(fr) |
85 | 89 | # we check the first parameter for the frame function is named 'self' |
86 | 90 | if len(args) and args[0] == "self": |
@@ -138,7 +142,7 @@ def f1(): |
138 | 142 | That was called by: f1 |
139 | 143 |
|
140 | 144 | """ |
141 | | - # https://stackoverflow.com/questions/5067604/determine-function-name-from-within-that-function-without-using-traceback # noqa |
| 145 | + # https://stackoverflow.com/questions/5067604/determine-function-name-from-within-that-function-without-using-traceback # noqa: E501 |
142 | 146 | try: |
143 | 147 | # noinspection PyProtectedMember |
144 | 148 | frame = sys._getframe(back + 2) |
@@ -241,7 +245,7 @@ def f1(): |
241 | 245 | # "0 back" is debug_callers, so "1 back" its caller |
242 | 246 | # https://docs.python.org/3/library/inspect.html |
243 | 247 | callers = [] # type: List[str] |
244 | | - frameinfolist = inspect.stack() # type: List[FrameInfo] # noqa |
| 248 | + frameinfolist = inspect.stack() # type: List[FrameInfo] |
245 | 249 | frameinfolist = frameinfolist[start_back:] |
246 | 250 | for frameinfo in frameinfolist: |
247 | 251 | frame = frameinfo.frame |
|
0 commit comments