Skip to content

[behavior-change] RUF010 delete unnecessary str() #4958

@smackesey

Description

@smackesey

IIUC, these two expressions are exactly equivalent:

f"{str(x)}"  # (1)
f"{x}"  # (2)

The str is superfluous in (1). But instead of RUF010 removing the str call, instead it autofixes to f"{x!s}"-- but the !s here is still superfluous-- the only time it makes sense to use !s is if there is an additional format specifier, e.g. f"{x!s:20}" (in this case str is applied before the format specifier, whereas without !s it is applied after the format specifier).

So IMO RUF010 should remove str() unless there is a format specifier, in which case it converts to !s.

Metadata

Metadata

Assignees

Labels

ruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions