1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-06-08 03:12:33 +03:00

Correct frame typing, and import clean up.

Also explains why we're doing that _getframe import that way.
This commit is contained in:
Athanasius 2020-07-28 09:19:34 +01:00
parent 589bc0b5f1
commit 45ef87bcb4

View File

@ -5,14 +5,13 @@ members on the logging.LogRecord instance for use in logging.Formatter()
strings. strings.
""" """
# So that any warning about accessing a protected member is only in one place.
from sys import _getframe as getframe from sys import _getframe as getframe
import inspect import inspect
import logging import logging
from typing import TYPE_CHECKING, Tuple from typing import Tuple
# if TYPE_CHECKING:
# TODO: Tests: # TODO: Tests:
# #
# 1. Call from bare function in file. # 1. Call from bare function in file.
@ -130,7 +129,7 @@ class EDMCContextFilter(logging.Filter):
# Go up through stack frames until we find the first with a # Go up through stack frames until we find the first with a
# type(f_locals.self) of logging.Logger. This should be the start # type(f_locals.self) of logging.Logger. This should be the start
# of the frames internal to logging. # of the frames internal to logging.
frame: 'frameobject' = getframe(0) frame: 'frame' = getframe(0)
while frame: while frame:
if isinstance(frame.f_locals.get('self'), logging.Logger): if isinstance(frame.f_locals.get('self'), logging.Logger):
frame = frame.f_back # Want to start on the next frame below frame = frame.f_back # Want to start on the next frame below