This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author r.david.murray
Recipients Ken.Basye, docs@python, eric.smith, r.david.murray
Date 2010-09-09.02:15:36
SpamBayes Score 9.314771e-14
Marked as misclassified No
Message-id <1283998538.57.0.159508718882.issue9805@psf.upfronthosting.co.za>
In-reply-to
Content
Python 3.2a2+ (py3k:84613, Sep  7 2010, 19:17:31) 
[GCC 4.4.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> "%s %(abc)s" % dict(abc=2)
"{'abc': 2} 2"

I did not expect this result.  Looks like a bug to me.

>>> "%s %(abc)s" % (dict(abc=2), 4)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: format requires a mapping
>>> "%d %(abc)s" % dict(abc=2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: %d format: a number is required, not dict
>>> "%s %s %(abc)s" % dict(abc=2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: not enough arguments for format string

So, the only case which "works" (but is arguably buggy) is a single %s mixed in with dict lookups.  'may' does not adequately describe this reality.  'must' is much closer.  If it weren't a backward incompatible change I'd suggest making a single dict (i.e.: non-tuple) argument to % with non-dict-lookup patterns an error.  As it is, we'll just live with the quirk, and probably with the bug as well.

I'm not sure it is worth explaining all these quirks in the main docs.  Perhaps in a footnote?
History
Date User Action Args
2010-09-09 02:15:41r.david.murraysetrecipients: + r.david.murray, eric.smith, docs@python, Ken.Basye
2010-09-09 02:15:38r.david.murraysetmessageid: <1283998538.57.0.159508718882.issue9805@psf.upfronthosting.co.za>
2010-09-09 02:15:36r.david.murraylinkissue9805 messages
2010-09-09 02:15:36r.david.murraycreate