[issue36787] Python3 regresison: String formatting of None object

2019-05-03 Thread Eric V. Smith


Eric V. Smith  added the comment:

This behavior isn't going to change. As Zach says, if you want to convert any 
value to a string, use !s. We want to fail as soon as possible: if a class 
(such as NoneType) doesn't implement __format__, then trying to format an 
instance with a format spec that doesn't apply to it should be an error. If you 
want to support strings or None, then it's your job to ensure the conversion.

As issue7994 says, one of the big drivers of this change (I'll argue it's 
really a bugfix) was that you could never add __format__ to  class if it didn't 
previously have one. Or if you did, it would have to support at least the 
string format spec, since there might be code that formatted it with "^10", for 
example.

As things currently stand, we could add __format__ to NoneType and have "T/F" 
mean convert to "True" or "False". If NoneTypes were already format-able with 
"^10", this change wouldn't be possible.

--
assignee:  -> eric.smith
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36787] Python3 regresison: String formatting of None object

2019-05-03 Thread Zachary Ware


Zachary Ware  added the comment:

You can use `!s` to be sure that the object is a string:

>>> '{!s:^10}'.format(None)
'   None   '

I think it's unlikely the behavior of NoneType.__format__ will be changed, but 
I'm adding Eric Smith to make that determination as the maintainer of 
str.format.

See issue7994 for the background on the change that produced this behavior.

--
nosy: +eric.smith, zach.ware
versions: +Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36787] Python3 regresison: String formatting of None object

2019-05-03 Thread Gawain Bolton


Gawain Bolton  added the comment:

Note: I have a patch which fixes this.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36787] Python3 regresison: String formatting of None object

2019-05-03 Thread Gawain Bolton


New submission from Gawain Bolton :

Python 2.7.16 (default, Apr  6 2019, 01:42:57)
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.  
  
>>> print('{:^10}'.format(None))
   None

However this does not work with Python3:
Python 3.7.3 (default, Apr  3 2019, 05:39:12)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.  
  
>>> print('{:^10}'.format(None))
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unsupported format string passed to NoneType.__format__

Given that the None type is output as a string, it makes sense for  
 string formatting options to be 
usable with it.  It also makes code 
 less fragile and avoids having to write special cases for when 
values 
could be None.

--
components: Library (Lib)
messages: 341355
nosy: Gawain Bolton
priority: normal
severity: normal
status: open
title: Python3 regresison: String formatting of None object
type: behavior

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com