Skip to content

Commit

Permalink
Merge b06dc92 into cb67a32
Browse files Browse the repository at this point in the history
  • Loading branch information
zsol committed Sep 25, 2018
2 parents cb67a32 + b06dc92 commit b09a233
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions black.py
Expand Up @@ -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 = ""
Expand Down
2 changes: 1 addition & 1 deletion tests/data/numeric_literals.py
Expand Up @@ -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 changes: 2 additions & 0 deletions tests/data/numeric_literals_py2.py
Expand Up @@ -3,6 +3,7 @@
x = 123456789L
x = 123456789l
x = 123456789
x = 0xb1acc

# output

Expand All @@ -12,3 +13,4 @@
x = 123456789L
x = 123456789L
x = 123456789
x = 0xB1ACC

0 comments on commit b09a233

Please sign in to comment.