Skip to content

RUF065 should not apply to the combination of %r and repr #20583

@dscorbett

Description

@dscorbett

Summary

logging-eager-conversion (RUF065) applies when a value is doubly converted with %r and repr. It should only apply to single conversions. Example:

$ cat >ruf065.py <<'# EOF'
import logging
logging.warning("%r", repr("1\n2"))
# EOF

$ python3.14 ruf065.py
WARNING:root:"'1\\n2'"

$ ruff --isolated check ruf065.py --select RUF065 --preview --output-format concise -q
ruf065.py:2:23: RUF065 Unnecessary `repr()` conversion when formatting with `%r`

Removing repr, as the rule suggests, changes the program’s behavior:

$ cat >ruf065_fixed.py <<'# EOF'
import logging
logging.warning("%r", "1\n2")
# EOF

$ python3.14 ruf065_fixed.py
WARNING:root:'1\n2'

The combinations that are currently supported and that would be appropriate to support (not that it’s required, but you might want to) are:

Code Function Currently supported Appropriate to support Replacement code
%s str ✅ Yes ✅ Yes %s
%r repr ✅ Yes ❌ No N/A
%s repr ❌ No ✅ Yes %r
%s ascii ❌ No ✅ Yes %a
%s oct ❌ No ✅ Yes %#o
%s hex ❌ No ✅ Yes %#x

Version

ruff 0.13.2 (b0bdf03 2025-09-25)

Metadata

Metadata

Assignees

No one assigned

    Labels

    previewRelated 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