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 barry, eli.bendersky, eric.smith, ethan.furman, serhiy.storchaka
Date 2013-08-14.22:06:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1376518000.28.0.981570167254.issue18738@psf.upfronthosting.co.za>
In-reply-to
Content
It's not whether a field width is specified that makes it "empty" or not, it's where there's anything in the format specifier at all. I'm trying to simplify the conversation by using format() instead of str.format(), but I'm not succeeding!

Going back to str.format examples:

'{}'.format(Test.one)
# equivalent to format(Test.one, '')
# result is Test.one.__format__('')

'{:d}'.format(Test.one)
# equivalent to format(Test.one, 'd')
# result is Test.one.__format__('d')

'{:}'.format(Test.one)
# equivalent to format(Test.one, '')
# result is Test.one.__format__('')

'{:10}'.format(Test.one)
# equivalent to format(Test.one, '10')
# result is Test.one.__format__('10')

In all of these cases, since there is no Test.one.__format__, int.__format__ is called. int.__format__ contains logic (Python/formatter_unicode.c, line 1422) that says "if the format specifier is empty, return str(self), otherwise do the int formatting". This is in order to comply with the previously mentioned PEP requirement. That's the only place where there's any "treat this as a str instead of an int" logic.

In order to avoid that logic, and cause more format specifiers to result in str-like behavior, we'll need to implement an __format__ somewhere (IntEnum, I guess) that makes the "int or str" decision.
History
Date User Action Args
2013-08-14 22:06:40eric.smithsetrecipients: + eric.smith, barry, eli.bendersky, ethan.furman, serhiy.storchaka
2013-08-14 22:06:40eric.smithsetmessageid: <1376518000.28.0.981570167254.issue18738@psf.upfronthosting.co.za>
2013-08-14 22:06:40eric.smithlinkissue18738 messages
2013-08-14 22:06:40eric.smithcreate