diff options
author | Florian Bruhin <me@the-compiler.org> | 2020-07-10 14:40:33 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2020-07-10 16:21:55 +0200 |
commit | 106a3a202ecf71c9620f513988e0af730adf0a44 (patch) | |
tree | 1ae9adfe57ff485130769101ddfea871c60afb59 | |
parent | 58765f2b8d263ad780cd8d9eeab83a7e3f6116c5 (diff) | |
download | qutebrowser-106a3a202ecf71c9620f513988e0af730adf0a44.tar.gz qutebrowser-106a3a202ecf71c9620f513988e0af730adf0a44.zip |
log: Set line number to -1 if it's None for Qt messages
If lineno is set to None in the LogRecord, pytest's logging formatting fails:
tests/unit/utils/test_log.py:418: in test_empty_message
log.qt_message_handler(QtCore.QtDebugMsg, self.Context(), "")
qutebrowser/utils/log.py:508: in qt_message_handler
qt.handle(record)
/usr/lib/python3.8/logging/__init__.py:1587: in handle
self.callHandlers(record)
/usr/lib/python3.8/logging/__init__.py:1649: in callHandlers
hdlr.handle(record)
/usr/lib/python3.8/logging/__init__.py:950: in handle
self.emit(record)
../../pytest/src/_pytest/logging.py:326: in emit
super().emit(record)
/usr/lib/python3.8/logging/__init__.py:1089: in emit
self.handleError(record)
/usr/lib/python3.8/logging/__init__.py:1081: in emit
msg = self.format(record)
/usr/lib/python3.8/logging/__init__.py:925: in format
return fmt.format(record)
../../pytest/src/_pytest/logging.py:89: in format
return super().format(record)
/usr/lib/python3.8/logging/__init__.py:667: in format
s = self.formatMessage(record)
/usr/lib/python3.8/logging/__init__.py:636: in formatMessage
return self._style.format(record)
../../pytest/src/_pytest/logging.py:185: in format
return self._fmt % record.__dict__
E TypeError: %d format: a number is required, not NoneType
According to typeshed, lineno should never be None:
https://github.com/python/typeshed/blob/028f0d52931fe1f96bb25d066186961159c1f801/stdlib/2and3/logging/__init__.pyi#L386
Thus, this is our fault, not pytest's. However, before pytest 6.0.0, pytest did
not surface logging errors:
https://github.com/pytest-dev/pytest/pull/7231
https://github.com/pytest-dev/pytest/commit/b13fcb23d79b3f38e497824c438c926a0a015561
Thus, we never noticed something was going wrong here.
(cherry picked from commit e206d346ced90aa4d8d8411baa1f9cc92406f16c)
Make mypy happy
It doesn't know about QMessageLogContext.lineno being Optional[int] rather than
int.
(cherry picked from commit 4136c847fdece2a0752e3029872a41bc41b103a3)
-rw-r--r-- | qutebrowser/utils/log.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/qutebrowser/utils/log.py b/qutebrowser/utils/log.py index 197f594f9..236bc392b 100644 --- a/qutebrowser/utils/log.py +++ b/qutebrowser/utils/log.py @@ -477,6 +477,11 @@ def qt_message_handler(msg_type: QtCore.QtMsgType, else: level = qt_to_logging[msg_type] + if context.line is None: + lineno = -1 # type: ignore[unreachable] + else: + lineno = context.line + if context.function is None: func = 'none' # type: ignore[unreachable] elif ':' in context.function: @@ -503,7 +508,7 @@ def qt_message_handler(msg_type: QtCore.QtMsgType, else: stack = None - record = qt.makeRecord(name, level, context.file, context.line, msg, (), + record = qt.makeRecord(name, level, context.file, lineno, msg, (), None, func, sinfo=stack) qt.handle(record) |