-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add underscores to numeric literals with more than 6 digits #529
Conversation
Pull Request Test Coverage Report for Build 751
💛 - Coveralls |
6a78d21
to
b607295
Compare
@JelleZijlstra thanks for reviewing :) We decided to just use underscores for numbers longer than 4 digits as that's simpler to understand for users (less surprising behavior) as well as |
Sure, that's fine with me too, probably better because it's a simpler rule. |
I like the idea but black is supposed to be the same for everyone and this would force western digit grouping onto all users. Concrete example: India would write 1_00_000 and not 100_000. https://en.wikipedia.org/wiki/Indian_numbering_system You wouldn't change quoted text strings, so why digits? |
Four digits is a little noisy, it's not really necessary for readability at that level. It would be way less controversial to standardize from six digits up. E.g.:
@Thalessa, thanks for bringing this up! The point of Black is to standardize everything so that code will look the same regardless of your project. Countries have differing standards, another popular example is the usage of a comma or a period for the decimal point separator (in Poland we use the comma). In this case, unless your project is local to the Indian subcontinent and does not anticipate any external contribution, standardizing on Indian separators is out of the question. So Black won't do that. However, I do recognize that if you were raised with the Indian numbering system in school, your brain is hard-wired now to read numbers like this. In other words, it's not just about the separators, it's about reading the numbers in your mind. Forcing an incompatible standard here is harsh. Thus, I think we need |
I'm reading about this some more now and in fact in Chinese numerals are grouped by tens-of-thousands:
This reinforces my thinking that we should let certain projects opt out with |
@@ -618,7 +636,8 @@ def format_str( | |||
remove_u_prefix=py36 or "unicode_literals" in future_imports, | |||
is_pyi=is_pyi, | |||
normalize_strings=normalize_strings, | |||
allow_underscores=py36, | |||
allow_underscores=py36 | |||
and not bool(mode & FileMode.NO_NUMERIC_UNDERSCORE_NORMALIZATION), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow this looks ugly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you rather have this be extra one-indented? That's possible but unprecedented in Black so far. We can also wrap the entire value in optional parentheses but then you will have four lines instead of two.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally prefer the optional parentheses even if it makes the expression break over 4 lines. Not sure if that is the best way to go in the general case, though.
No description provided.