[issue18738] % formatting incomplete for Enum

2013-08-14 Thread Eli Bendersky
Eli Bendersky added the comment: On Wed, Aug 14, 2013 at 6:55 AM, Serhiy Storchaka wrote: > > Serhiy Storchaka added the comment: > > `.format()` is surprised too. > > >>> '{:}'.format(AF.IPv4) > 'AF.IPv4' > >>> '{:10}'.format(AF.IPv4) > ' 1' > > Oh, this looks like a bug in str.format (

[issue18738] % formatting incomplete for Enum

2013-08-14 Thread Eli Bendersky
Eli Bendersky added the comment: Ethan, str.format uses __format__. We don't seem to provide a custom one. -- ___ Python tracker ___ _

[issue18738] % formatting incomplete for Enum

2013-08-14 Thread Ethan Furman
Ethan Furman added the comment: Looks like Objects/unicodeobject.c needs the same enhancement that Modules/_json.c received: convert int/float subclasses into actual ints/floats before continuing. -- ___ Python tracker

[issue18738] % formatting incomplete for Enum

2013-08-14 Thread Ethan Furman
Ethan Furman added the comment: '{:}'.format(AF.IPv4) is incorrect, but '{:10}'.format(AF.IPv4) behaves as it should. -- ___ Python tracker ___ _

[issue18738] % formatting incomplete for Enum

2013-08-14 Thread Eli Bendersky
Eli Bendersky added the comment: In Objects/unicodeobject.c when it gets into mainformatlong, an IntEnum is recognized as an integer (passes PyLong_Check) and goes into formatlong. There, in the cases of 'd', 'i', 'u' it has: case 'u': /* Special-case boolean: we want 0/1 */

[issue18738] % formatting incomplete for Enum

2013-08-14 Thread Eric V. Smith
Changes by Eric V. Smith : -- nosy: +eric.smith ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.pyt

[issue18738] % formatting incomplete for Enum

2013-08-14 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: `.format()` is surprised too. >>> '{:}'.format(AF.IPv4) 'AF.IPv4' >>> '{:10}'.format(AF.IPv4) ' 1' -- ___ Python tracker ___

[issue18738] % formatting incomplete for Enum

2013-08-14 Thread Ethan Furman
New submission from Ethan Furman: While `.format()` works fine with enum, %-formatting does not: --> class AF(enum.IntEnum): ... IPv4 = 1 ... IPv6 = 2 ... --> AF.IPv4 --> '%s' % AF.IPv4 'AF.IPv4' --> '%r' % AF.IPv4 '' --> '%d' % AF.IPv4 'AF.IPv4' --> '%i' % AF.IPv4 'AF.IPv4' --> '%x'