Uppercase digits in hex literals (#530)
This commit is contained in:
parent
cb67a32242
commit
bbf38400ce
@ -374,7 +374,8 @@ an adoption helper, avoid using this for new projects.
|
||||
|
||||
### Numeric literals
|
||||
|
||||
*Black* standardizes most numeric literals to use lowercase letters: `0xab`
|
||||
*Black* standardizes most numeric literals to use lowercase letters for the
|
||||
syntactic parts and uppercase letters for the digits themselves: `0xAB`
|
||||
instead of `0XAB` and `1e10` instead of `1E10`. Python 2 long literals are
|
||||
styled as `2L` instead of `2l` to avoid confusion between `l` and `1`. In
|
||||
Python 3.6+, *Black* adds underscores to long numeric literals to aid
|
||||
|
8
black.py
8
black.py
@ -2542,9 +2542,13 @@ def normalize_numeric_literal(leaf: Leaf, allow_underscores: bool) -> None:
|
||||
in Python 2 long literals), and long number literals are split using underscores.
|
||||
"""
|
||||
text = leaf.value.lower()
|
||||
if text.startswith(("0o", "0x", "0b")):
|
||||
# Leave octal, hex, and binary literals alone.
|
||||
if text.startswith(("0o", "0b")):
|
||||
# Leave octal and binary literals alone.
|
||||
pass
|
||||
elif text.startswith("0x"):
|
||||
# Change hex literals to upper case.
|
||||
before, after = text[:2], text[2:]
|
||||
text = f"{before}{after.upper()}"
|
||||
elif "e" in text:
|
||||
before, after = text.split("e")
|
||||
sign = ""
|
||||
|
@ -34,7 +34,7 @@
|
||||
x = 123_456_789e123_456_789
|
||||
x = 123_456_789j
|
||||
x = 123_456_789.123_456_789j
|
||||
x = 0xb1acc
|
||||
x = 0xB1ACC
|
||||
x = 0b1011
|
||||
x = 0o777
|
||||
x = 0.000_000_006
|
||||
|
@ -3,6 +3,7 @@
|
||||
x = 123456789L
|
||||
x = 123456789l
|
||||
x = 123456789
|
||||
x = 0xb1acc
|
||||
|
||||
# output
|
||||
|
||||
@ -12,3 +13,4 @@
|
||||
x = 123456789L
|
||||
x = 123456789L
|
||||
x = 123456789
|
||||
x = 0xB1ACC
|
||||
|
Loading…
Reference in New Issue
Block a user