Don't enable warnings if log was never inited
Otherwise, anything importing qtutils (which uses ignore_py_warnings on module level) would enable warnings. This means pylint showed its own warnings because of qute_pylint.config.
This commit is contained in:
parent
c3f53312af
commit
1564563662
@ -38,6 +38,8 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
colorama = None
|
colorama = None
|
||||||
|
|
||||||
|
_log_inited = False
|
||||||
|
|
||||||
COLORS = ['black', 'red', 'green', 'yellow', 'blue', 'purple', 'cyan', 'white']
|
COLORS = ['black', 'red', 'green', 'yellow', 'blue', 'purple', 'cyan', 'white']
|
||||||
COLOR_ESCAPES = {color: '\033[{}m'.format(i)
|
COLOR_ESCAPES = {color: '\033[{}m'.format(i)
|
||||||
for i, color in enumerate(COLORS, start=30)}
|
for i, color in enumerate(COLORS, start=30)}
|
||||||
@ -169,6 +171,8 @@ def init_log(args):
|
|||||||
logging.captureWarnings(True)
|
logging.captureWarnings(True)
|
||||||
_init_py_warnings()
|
_init_py_warnings()
|
||||||
QtCore.qInstallMessageHandler(qt_message_handler)
|
QtCore.qInstallMessageHandler(qt_message_handler)
|
||||||
|
global _log_inited
|
||||||
|
_log_inited = True
|
||||||
|
|
||||||
|
|
||||||
def _init_py_warnings():
|
def _init_py_warnings():
|
||||||
@ -189,9 +193,10 @@ def disable_qt_msghandler():
|
|||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def ignore_py_warnings(**kwargs):
|
def ignore_py_warnings(**kwargs):
|
||||||
"""Contextmanager to temporarily hke certain Python warnings."""
|
"""Contextmanager to temporarily disable certain Python warnings."""
|
||||||
warnings.filterwarnings('ignore', **kwargs)
|
warnings.filterwarnings('ignore', **kwargs)
|
||||||
yield
|
yield
|
||||||
|
if _log_inited:
|
||||||
_init_py_warnings()
|
_init_py_warnings()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user