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.

Title: string, center, ljust, rjust, width paramter should accept None
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.5
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: glenflet, rhettinger
Priority: low Keywords:

Created on 2015-04-29 06:44 by glenflet, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg242215 - (view) Author: Glen Fletcher (glenflet) Date: 2015-04-29 06:44
I've only list python 2.7, as I'm not sure that version 3 doesn't accept None, if so this should be changed there too.

If these function are passed None, as the width they should return the string unchanged, just as they would for with a width set to 0.

Reasoning, A common use of these would be in list comprehensions and such, i.e. (, w) for i, w in items, widths), given the that items and widths may be of differing length in theory i should be a empty string and width 0 it not specified however the best way of dealing with this would be to use itertools.izip_longest(items, widths, default=None) and None would be encode as No Value, however this would require writing (, 0 if w is None else w) for i, w in itertools.izip_longest(items, widths, default=None)), which is far harder to follow, when its quite reasonable to expect these string alignment functions to return an unpadded string if passed None as the width.
msg242217 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-04-29 08:14
Sorry, this use case seems contrived.   The common use case for centering is with a known width (otherwise, what is the point).  Also, it isn't hard to write something like: or 0)
msg242297 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-05-01 01:44
Marking as rejected because 0 works fine and accepting None just complicates the parsing and documentation without any incremental benefit.
Date User Action Args
2022-04-11 14:58:16adminsetgithub: 68262
2015-05-01 01:45:00rhettingersetstatus: open -> closed
resolution: rejected
messages: + msg242297
2015-04-29 08:14:35rhettingersetpriority: normal -> low
versions: + Python 3.5, - Python 2.7
nosy: + rhettinger

messages: + msg242217

type: behavior -> enhancement
2015-04-29 06:44:04glenfletcreate