IronLanguages / main

Work for this repo has moved to https://github.com/IronLanguages/ironpython2
1.16k stars 347 forks source link

String formatting of `bool` type #1629

Closed michaelblyons closed 7 years ago

michaelblyons commented 7 years ago

IronPython 2.7.7rc2

>>> '{}'.format(True) # Want 'True'
'True'
>>> '{:^10}'.format(True) # Want '   True   ', right?
'True'

Default Python2 (and maybe Python3?) do not handle this super-well either. They appear to apply int() formatting:

>>> '{:^10}'.format(True)
'     1    '

All cases can be coerced with ...format(str(True)), but it's kind of weird to expect padding and receive none.

slozier commented 7 years ago

Looks like the format spec is ignored for bool: https://github.com/IronLanguages/main/blob/827af8c068d823629945ce3bf76febb7a5f79c9b/Languages/IronPython/IronPython/Runtime/Operations/BoolOps.cs#L92

Side note: We should probably match the CPython behavior and display a number when formatting with an alignment.