Alan Briolat added the comment:
Because the object in question is not actually a dict, LogRecord is attempting,
in this example, "%(bar)s" % (f,) instead of "%(bar)s" % f.
In unicodeobject.c this causes the PyMapping_Check in PyUnicode_Format to fail
because it's a tuple (note that PyMapping_Check *only* checks for the
__getitem__ attribute), the argument to not be treated as a dict, and
consequently ctx.dict = NULL for the format operation.
This condition, combined with still attempting to resolve named values in the
format string, causes unicode_format_arg_parse to raise the TypeError("format
requires a mapping").
Speaking of documentation, the language of
https://docs.python.org/2/library/logging.html#logging.Logger.debug
strongly suggests that logging.debug(msg, args...) should be considered
equivalent to logging.debug(msg % args...), which still means this is still
"unexpected" behaviour. The intention is clearly to allow this special case to
pass through to the formatting operator unimpeded, however this doesn't happen.
Also, even if "the mapping protocol" should remain the key concept (the
behaviour of PyMapping_Check being a happy accident), checking for
isinstance(..., dict) is still wrong - it should at least be
collections.Mapping to give users a chance to emulate the correct interface.
----------
status: pending -> open
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue21172>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com