Author alan.briolat
Recipients alan.briolat, vinay.sajip
Date 2014-04-08.12:19:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1396959589.33.0.585279288772.issue21172@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2014-04-08 12:19:49alan.briolatsetrecipients: + alan.briolat, vinay.sajip
2014-04-08 12:19:49alan.briolatsetmessageid: <1396959589.33.0.585279288772.issue21172@psf.upfronthosting.co.za>
2014-04-08 12:19:49alan.briolatlinkissue21172 messages
2014-04-08 12:19:48alan.briolatcreate