Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Option to use lowercase hex literals #10432

Open
DavidBuchanan314 opened this issue Mar 16, 2024 · 4 comments
Open

Feature request: Option to use lowercase hex literals #10432

DavidBuchanan314 opened this issue Mar 16, 2024 · 4 comments
Labels
formatter Related to the formatter style How should formatted code look

Comments

@DavidBuchanan314
Copy link

For a brief time window, black had this feature, before it was reverted psf/black#1692

I'm a big fan of lowercase hex literals, for most of the practical reasons outlined in the above issue, and also for purely aesthetic reasons - uppercase feels shouty.

If I had my way I'd make lowercase the default, but failing that it'd be great to have a configuration option.

@zanieb zanieb added formatter Related to the formatter style How should formatted code look labels Mar 17, 2024
@MichaReiser
Copy link
Member

Hi @DavidBuchanan314

If I understand correctly, this is about formatting hex number literals like 0xEF? I'm asking because Ruff normalizes hex numbers in string literals to lowercase Playground

My preference would be to change the default to lowercase to make it consistent with hex formatting in strings. However, from reading through Black's issues and discussions on the string hex formatting PRs, I understand that Black changed the preferred casing for hex number literals multiple times and that it's unlikely that they'll change it again in the future. I don't know if I want to deviate from Black's default, considering that the benefits are marginal.

That means that supporting lowercase hex formatting most likely requires adding a new formatter option. I'm not opposed to this, but we need to make a holistic decision if we want to support formatting-related options or keep Black's opinionated stance to have no-formatting-related settings (or very limited).

@DavidBuchanan314
Copy link
Author

Yeah, it's the number literals I'm interested in. As for whether it's actually worth it, I guess I'll leave that to everyone else to decide :)

@kaddkaka
Copy link

To me this kind of configuration is great. It shouldn't affect other formatting and it allows to adopt ruff formatting on an existing codebase that uses either style.

I would also like to propose three values for this kind of config:

  • uppercase
  • lowercase
  • dont_touch (any_case)

The last option let's the programmer choose case and don't modify it with the formatter - this should make the formatter faster 🐎

@Avasam
Copy link

Avasam commented Apr 3, 2024

Piggybacking here a bit, but I was quite surprised when "Ruff format" changed the content of a hex string 1, and perplexed that the preference for string and number literal is different.

"don't touch" or "off" option is also great to introduce to existing code bases.

Footnotes

  1. That was on a project already currently checked with black. Maybe black just didn't detect that case. I know it also doesn't change the value, still surprising nonetheless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter style How should formatted code look
Projects
None yet
Development

No branches or pull requests

5 participants