PEP 737 – Unify type name formatting

The existing string format specification is used by numbers: __format__() methods of int, float, complex, and decimal.Decimal.

I propose to have a different format spec only used by type.__format__(). Are there reasons to use the same format spec for all stdlib types?

There are other existing stdlib types which use a different format spec, such as datetime.datetime:

>>> import datetime; d=datetime.datetime.now(); f"{d:at %Hh%M}"
'at 22h56'

Other examples:

  • ipaddress.IPv4Address: b, X, x and n formats
  • fractions.Fraction: use the same format spec than int
  • enum.Enum: similar to format(str(value), format_spec)
2 Likes