Skip to content

RUF065 should ignore str when not used for conversion #21315

@dscorbett

Description

@dscorbett

Summary

logging-eager-conversion (RUF065) should only treat str as an unnecessary conversion when it has exactly one argument and that argument isn’t starred. Otherwise, the str call is doing something else and can’t be so straightforwardly removed. Example:

$ cat >ruf065.py <<'# EOF'
import logging
logging.warning("%s", str())
logging.warning("%s", str(b"\xe2\x9a\xa0", "utf-8"))
logging.warning("%s", str(*(b"\xf0\x9f\x9a\xa7", "utf-8")))
logging.warning("%s", str(**{"object": b"\xf0\x9f\x9a\xa8", "encoding": "utf-8"}))
# EOF

$ ruff --isolated check ruf065.py --select RUF065 --preview --output-format concise -q
ruf065.py:2:23: RUF065 Unnecessary `str()` conversion when formatting with `%s`
ruf065.py:3:23: RUF065 Unnecessary `str()` conversion when formatting with `%s`
ruf065.py:4:23: RUF065 Unnecessary `str()` conversion when formatting with `%s`
ruf065.py:5:23: RUF065 Unnecessary `str()` conversion when formatting with `%s`

Version

ruff 0.14.4 (c7ff982 2025-11-06)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpreviewRelated to preview mode featuresruleImplementing 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