From 15645636626a3635e906cb3f36d0c83204a154cf Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 25 Jul 2016 13:03:58 +0200 Subject: [PATCH] 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. --- qutebrowser/utils/log.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/qutebrowser/utils/log.py b/qutebrowser/utils/log.py index a1210caf0..18bec85f7 100644 --- a/qutebrowser/utils/log.py +++ b/qutebrowser/utils/log.py @@ -38,6 +38,8 @@ try: except ImportError: colorama = None +_log_inited = False + COLORS = ['black', 'red', 'green', 'yellow', 'blue', 'purple', 'cyan', 'white'] COLOR_ESCAPES = {color: '\033[{}m'.format(i) for i, color in enumerate(COLORS, start=30)} @@ -169,6 +171,8 @@ def init_log(args): logging.captureWarnings(True) _init_py_warnings() QtCore.qInstallMessageHandler(qt_message_handler) + global _log_inited + _log_inited = True def _init_py_warnings(): @@ -189,10 +193,11 @@ def disable_qt_msghandler(): @contextlib.contextmanager def ignore_py_warnings(**kwargs): - """Contextmanager to temporarily hke certain Python warnings.""" + """Contextmanager to temporarily disable certain Python warnings.""" warnings.filterwarnings('ignore', **kwargs) yield - _init_py_warnings() + if _log_inited: + _init_py_warnings() def _init_handlers(level, color, force_color, json_logging, ram_capacity):