New submission from Oren <oren.leaf...@gmail.com>:

In python2, calling Handler.handleError may not be strictly correct, but it 
doesn't raise an exception. However, this has regressed since this patch:
https://hg.python.org/cpython/rev/d7b868cdd9bb

$ cat logbug.py
import logging

class CustomHandler(logging.Handler):
    def transmit(self, record):
        return False
    def emit(self, record):
        if not self.transmit(record):
            self.handleError(record)
def main():
    logger = logging.getLogger()
    logger.addHandler(CustomHandler())
    logger.warning('this will work in python 2.7, but not 3')

if __name__ == '__main__':
    main()

$ python2 logbug.py
None
Logged from file logbug.py, line 15

$ python3 logbug.py
--- Logging error ---
NoneType: None
Call stack:
Traceback (most recent call last):
  File "logbug.py", line 20, in <module>
    main()
  File "logbug.py", line 15, in main
    logger.warning('this will work in python 2.7, but not 3')
  File 
"/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py",
 line 1318, in warning
    self._log(WARNING, msg, args, **kwargs)
  File 
"/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py",
 line 1442, in _log
    self.handle(record)
  File 
"/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py",
 line 1452, in handle
    self.callHandlers(record)
  File 
"/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py",
 line 1514, in callHandlers
    hdlr.handle(record)
  File 
"/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py",
 line 863, in handle
    self.emit(record)
  File "logbug.py", line 9, in emit
    self.handleError(record)
  File 
"/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py",
 line 920, in handleError
    frame = tb.tb_frame
AttributeError: 'NoneType' object has no attribute 'tb_frame'

----------
components: Library (Lib)
messages: 321391
nosy: orenl
priority: normal
severity: normal
status: open
title: logging.Handler.handleError regressed in python3
versions: Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue34086>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to