All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
2 Formatting numeric literals.
5 from blib2to3.pytree import Leaf
8 def format_hex(text: str) -> str:
10 Formats a hexadecimal string like "0x12B3"
12 before, after = text[:2], text[2:]
13 return f"{before}{after.upper()}"
16 def format_scientific_notation(text: str) -> str:
17 """Formats a numeric string utilizing scentific notation"""
18 before, after = text.split("e")
20 if after.startswith("-"):
23 elif after.startswith("+"):
25 before = format_float_or_int_string(before)
26 return f"{before}e{sign}{after}"
29 def format_complex_number(text: str) -> str:
30 """Formats a complex string like `10j`"""
33 return f"{format_float_or_int_string(number)}{suffix}"
36 def format_float_or_int_string(text: str) -> str:
37 """Formats a float string like "1.0"."""
41 before, after = text.split(".")
42 return f"{before or 0}.{after or 0}"
45 def normalize_numeric_literal(leaf: Leaf) -> None:
46 """Normalizes numeric (float, int, and complex) literals.
48 All letters used in the representation are normalized to lowercase."""
49 text = leaf.value.lower()
50 if text.startswith(("0o", "0b")):
51 # Leave octal and binary literals alone.
53 elif text.startswith("0x"):
54 text = format_hex(text)
56 text = format_scientific_notation(text)
57 elif text.endswith("j"):
58 text = format_complex_number(text)
60 text = format_float_or_int_string(text)