Open guillp opened 3 months ago
Thanks for the rule idea.
https://github.com/astral-sh/ruff/issues/3693 covers the handling of large numbers. The issue also points out that one challenge with such a rule is that different cultures use different grouping. That means the rule has to be configurable (although we could decide to skip this initially). It would be great to have a design for how different culture norms could be supported by the rule.
In my opinion, hexadecimal and binary numbers should have their own rules. I can see users who want to enforce strict number formatting but want more freedom when it comes to binary notation. The good thing is that it means we can add those rules one by one.
My only concern with these rules is that they potentially overlap with the formatter. Although I think it's unlikely that the formatter wants to be opinionated about the formatting.
@AlexWaygood what's your take on these rules?
I would like to implement a rule for PEP 515. This allows using underscores as visual separators in numerics. Large numbers are hard to read and using underscore as thousands, millions, etc. separators increases readability a lot.
E.g this would turn this:
into:
A few things I have in mind:
0x15_DEAD_BEEF
). Would it make sense to left-pad with 0 to have a length that is a multiple of 4 (so0x0015_DEAD_BEEF
) ?0b1100110_01101111_01101111
). Would it make sense to left pad with 0 up to a multiple of 8 (so0b01100110_01101111_01101111
) ?I did not find any prior art so if such a rule exists somewhere else, feel free to point me to it as well.
This would be my first Ruff rule and one of my first experiments with Rust, so I'm looking for feedback about the rule itself before I start coding it. If you feel this is not implementable for any reason, just let me know as well :)