Title: __format__ method not implemented for boolean types - uses int
Type: behaviour Severity: minor
Components: Core Versions: Jython 2.7
Status: open Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: _peter_holloway, jeff.allen
Priority: normal Keywords: easy

Created on 2018-06-12.11:17:48 by _peter_holloway, last changed 2018-08-10.21:10:44 by jeff.allen.

msg12008 (view) Author: Peter Holloway (_peter_holloway) Date: 2018-06-12.11:17:48
In cPython 2.7.12, '{}'.format(True) results in the string 'True'.

In Jython 2.7.1, the same line results in '1'.
msg12078 (view) Author: Jeff Allen (jeff.allen) Date: 2018-08-10.21:10:43
This isn't as obviously wrong as it looks at first.

I would say we have followed the convention that no type means "d":
>>> True.__format__("10")
'         1'
>>> True.__format__("<")
>>> True.__format__("d")

But we missed the convention that an empty format string ("") produces the same result as if you had called str() on the value.
>>> True.__format__("")


I'm surprised that nothing in the regression tests has caught this, but there just isn't one in the Python suite. So a solution should start with a failing test in (I think) test_format_jy checking this for True and False, and maybe a few where it is 1, 0 for good measure.
Date User Action Args
2018-08-10 21:10:44jeff.allensetkeywords: + easy
priority: normal
resolution: accepted
messages: + msg12078
nosy: + jeff.allen
2018-06-12 11:17:48_peter_hollowaycreate