Skip to content

UP012 fix does not handle non-bytes escape sequences #12753

@dscorbett

Description

@dscorbett

When converting string literals to bytes literals, UP012 does not handle escape sequences that are only recognized in string literals. It should convert them to literal characters or to recognized escape sequences.

$ ruff --version
ruff 0.5.6
$ cat up012.py
print("\N{DIGIT ONE}".encode())
print("\u0031".encode())
print("\U00000031".encode())
$ python up012.py 
b'1'
b'1'
b'1'
$ ruff check --isolated --select UP012 up012.py --fix
Found 3 errors (3 fixed, 0 remaining).
$ python up012.py
b'\\N{DIGIT ONE}'
b'\\u0031'
b'\\U00000031'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions