astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
28.65k stars 927 forks source link

PLR6104 rewrites numbers w/o the base indicator #11672

Open Avasam opened 1 month ago

Avasam commented 1 month ago

input

test = 0x5
test = test + 0xBA

test2 = b""
test2 = test2 + b"\000"

Run ruff check --fix --unsafe-fixes --preview --select=PLR6104 --isolated

output

test = 0x5
test += 186

test2 = b""
test2 += b"\x00"

Ruff version 0.4.7

charliermarsh commented 1 month ago

Yeah, common theme with Generator usage, we don't preserve verbatim numbers.

dhruvmanila commented 4 weeks ago

Once #11457 is completed, this can be solved by including number related flags on TokenFlags, propagating it to the NumberLiteral node and using that in the Generator. This would be similar to the flags on the string nodes. This is actually one of the potential use-case me and Micha discussed for TokenFlags.