Repository: psf/black
File: src/black/__init__.py (Python)

Code before:


def normalize_numeric_literal(leaf: Leaf) -> None:
    """Normalizes numeric (float, int, and complex) literals.

    All letters used in the representation are normalized to lowercase (except
    in Python 2 long literals).
    """
    text = leaf.value.lower()
    if text.startswith(("0o", "0b")):
        # Leave octal and binary literals alone.
        pass
    elif text.startswith("0x"):
        text = format_hex(text)
    elif "e" in text:
        text = format_scientific_notation(text)
    elif text.endswith(("j", "l")):
        text = format_long_or_complex_number(text)
    else:
        text = format_float_or_int_string(text)
    leaf.value = text


def format_hex(text: str) -> str:
    """
    Formats a hexidecimal strign like "0x12b3"

    Uses lowercase because of similarity between "B" and "8", which
    can cause security issues.
    see: https://github.com/psf/black/issues/1692
    """

    before, after = text[:2], text[2:]
    return f"{before}{after.lower()}"


def format_scientific_notation(text: str) -> str:
    """Formats a numeric string utilizing scentific notation"""
    before, after = text.split("e")
    sign = ""
    if after.startswith("-"):
        after = after[1:]
        sign = "-"
    elif after.startswith("+"):
        after = after[1:]
    before = format_float_or_int_string(before)
    return f"{before}e{sign}{after}"


def format_long_or_complex_number(text: str) -> str:
    """Formats a long or complex string like `10L` or `10j`"""

Review comment (suggestion):
```suggestion
    Formats a hexadecimal string like "0x12b3"
```

Code after:
                return

    if new_quote == '"""' and new_body[-1:] == '"':
        # edge case:
        new_body = new_body[:-1] + '\\"'
    orig_escape_count = body.count("\\")
    new_escape_count = new_body.count("\\")
    if new_escape_count > orig_escape_count:
        return  # Do not introduce more escaping

    if new_escape_count == orig_escape_count and orig_quote == '"':
        return  # Prefer double quotes

    leaf.value = f"{prefix}{new_quote}{new_body}{new_quote}"


def normalize_numeric_literal(leaf: Leaf) -> None:
    """Normalizes numeric (float, int, and complex) literals.

    All letters used in the representation are normalized to lowercase (except
    in Python 2 long literals).
    """
    text = leaf.value.lower()
    if text.startswith(("0o", "0b")):
        # Leave octal and binary literals alone.
        pass
    elif text.startswith("0x"):
        text = format_hex(text)
    elif "e" in text:
        text = format_scientific_notation(text)
    elif text.endswith(("j", "l")):
        text = format_long_or_complex_number(text)
    else:
        text = format_float_or_int_string(text)
    leaf.value = text


def format_hex(text: str) -> str:
    """
    Formats a hexadecimal string like "0x12b3"

    Uses lowercase because of similarity between "B" and "8", which
    can cause security issues.
    see: https://github.com/psf/black/issues/1692
    """

    before, after = text[:2], text[2:]
    return f"{before}{after.lower()}"


def format_scientific_notation(text: str) -> str: