Closed DimitriPapadopoulos closed 2 weeks ago
how do you know they are useless?
Isn't str()
the default conversion?
I don't actually know, but I do know that officially !s
is redundant: https://peps.python.org/pep-0498/#s-r-and-a-are-redundant, so if we do want to be sure we are calling str()
in the fstring we should directly call str
.
But I'd like to know why those !s were added before we remove them
From PEP 3101:
Explicit Conversion Flag
The explicit conversion flag is used to transform the format field value before it is formatted. This can be used to override the type-specific formatting behavior, and format the value as if it were a more generic type.
In the absence of an explicit conversion flag, the value is simply formatted. The default formatting converts to a str
:
Controlling Formatting on a Per-Type Basis
[...] The
object.__format__
method is the simplest: It simply converts the object to a string, and then calls format again:class object: def __format__(self, format_spec): return format(str(self), format_spec)
I don't think !s
was added for a reason here.
Remove useless
!s
inf"...{...!s}..."
.