[New-bugs-announce] [issue21172] Unexpected behaviour with logging.LogRecord "first arg is dict" case

Alan Briolat report at bugs.python.org
Mon Apr 7 19:04:37 CEST 2014


New submission from Alan Briolat:

The logging.LogRecord class is more restrictive with its "first arg is dict" case than the formatting operator it uses requires.  As far as I can tell, for "%(foo)s" % bar, the minimum contract is that bar.__getitem__("foo") succeeds, not that bar is an instance of dict.  However, fulfilling only this minimum contract results in LogRecord raising an exception at the point of applying the string format, which is confusing considering the "same" expression succeeds outside of logging.  See the attached file for how 2 "equivalent" expressions behave completely differently.

For resolution, I wonder if checking for "hasattr(..., '__getitem__')" instead of "isinstance(..., dict)" would be sufficient?

----------
components: Library (Lib)
files: logging_format_bug.py
messages: 215713
nosy: alan.briolat
priority: normal
severity: normal
status: open
title: Unexpected behaviour with logging.LogRecord "first arg is dict" case
type: behavior
versions: Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5
Added file: http://bugs.python.org/file34750/logging_format_bug.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21172>
_______________________________________


More information about the New-bugs-announce mailing list