string formatting supports implicit strifying. However, string format specifiers don't appear to be compatible with this, only explicit str objects (regardless of using type=s). I cannot find this behavior documented anywhere without pulling up the cpython code. default ubuntu 20.04 python3.8 install. using an explicit str() call is workable but it's not very clean especially in my use case where it now liters the code.
obj = object()
explicit = str(obj)
print(f"{explicit:.5}")
print(f"{obj}")
print(f"{obj:.5}") # TypeError: unsupported format string passed to object.__format__
Question:
- Have I interpreted this correctly
- where should I be looking to glean this info myself (if exists outside cpython code), and
- is there any way accomplish format specifiers
{:...}while relying on the implicitstr()ification?