Commit bbf38400 authored by Zsolt Dollenstein's avatar Zsolt Dollenstein Committed by Łukasz Langa
Browse files

Uppercase digits in hex literals (#530)

parent cb67a322
Loading
Loading
Loading
Loading
+2 −1
Changes for README.md: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -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
+6 −2
Changes for black.py: 6 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -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 = ""
+1 −1
Changes for tests/data/numeric_literals.py: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -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
+2 −0
Changes for tests/data/numeric_literals_py2.py: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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