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.

classification
Title: alighment format for nullable values
Type: enhancement Stage:
Components: Interpreter Core Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Anthony Sottile, eric.smith
Priority: normal Keywords:

Created on 2021-09-10 15:10 by Anthony Sottile, last changed 2022-04-11 14:59 by admin.

Messages (3)
msg401582 - (view) Author: Anthony Sottile (Anthony Sottile) * Date: 2021-09-10 15:10
currently this works correctly:

```
>>> '%8s %8s' % (None, 1)
'    None        1'
```

but conversion to f-string fails:

```
>>> f'{None:>8} {1:>8}'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported format string passed to NoneType.__format__
```

my proposal is to implement alignment `__format__` for `None` following the same as for `str` for alignment specifiers
msg401583 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-09-10 15:39
Why would you only want alignment, and not all string formatting options?

And if that's the case, just convert it to a string: 

>>> f'{None!s:>8} {1:>8}'
'    None        1'
msg401600 - (view) Author: Anthony Sottile (Anthony Sottile) * Date: 2021-09-10 16:45
alignment was the only one I found which was applicable and didn't work

`!s` "works" but it's kind of a hack (of course I want string formatting, I'm making a string!) -- then I would want to write `!s` everywhere which is cumbersome and ugly
History
Date User Action Args
2022-04-11 14:59:49adminsetgithub: 89328
2021-09-10 16:45:08Anthony Sottilesetmessages: + msg401600
2021-09-10 15:39:24eric.smithsettype: behavior -> enhancement
versions: - Python 3.10
2021-09-10 15:39:04eric.smithsetnosy: + eric.smith
messages: + msg401583
2021-09-10 15:10:56Anthony Sottilecreate