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 eric.smith
Recipients eric.smith, ezio.melotti, r.david.murray
Date 2014-02-06.01:08:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1391648895.25.0.489864889072.issue20524@psf.upfronthosting.co.za>
In-reply-to
Content
int, float, str, and complex are the types formatted by that code.

Notice that Decimal already has a better message:

>>> format(Decimal(42), 'tx')
Traceback (most recent call last):
  ...
ValueError: Invalid format specifier: tx

>>> format(42, 'tx')
Traceback (most recent call last):
  ...
ValueError: Invalid conversion specification

But, look at this:
>>> format(3, '--')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Unknown format code '-' for object of type 'int'

This is generated in unknown_presentation_type, also in formatter_unicode.c. It almost does what you want, but just handles the presentation type, not the whole format specifier.

Error handling could be cleaned up in that module. I'd say that the string should be:
"<specific error> with format specifier <specifier> for object of type '<type>'"

<specific error> might be "Unknown presentation type '-'", or "Cannot specify ','".

I think that would require some major surgery to the code, but would be worth it.

Note that in your original example, you want the error to contain "{length:%HH:%MM}". By the time the error is detected, the only thing the code knows is the format specifier "%HH:%MM". It doesn't know the "length" part. The error is basically in int.__format__. By the time that gets called, the format specifier has already been extracted and the argument selection (by indexing, by name, including attribute access) has already taken place.
History
Date User Action Args
2014-02-06 01:08:15eric.smithsetrecipients: + eric.smith, ezio.melotti, r.david.murray
2014-02-06 01:08:15eric.smithsetmessageid: <1391648895.25.0.489864889072.issue20524@psf.upfronthosting.co.za>
2014-02-06 01:08:15eric.smithlinkissue20524 messages
2014-02-06 01:08:14eric.smithcreate