Skip to content

RUF010 fix should be unsafe when it deletes a comment #19745

@dscorbett

Description

@dscorbett

Summary

The fix for explicit-f-string-type-conversion (RUF010) should be marked unsafe when it deletes a comment. Example:

$ cat >ruf010.py <<'# EOF'
f"{ascii(
    # comment
    1
)}"
# EOF

$ ruff --isolated check ruf010.py --select RUF010 --fix
Found 1 error (1 fixed, 0 remaining).

$ cat ruf010.py 
f"{1!a}"

When the modified code includes a comment and the comment is preserved, the fix should continue to be marked safe. Example:

f"{ascii((
    # comment
    1
))}"

Version

ruff 0.12.7 (c5ac998 2025-07-29)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixesRelated to suggested fixes for violationshelp wantedContributions especially welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions