Skip to content

Commit af13b7e

Browse files
move _SUPERSCRIPT_MAP and switch to list comprehension
1 parent 12b43e0 commit af13b7e

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

src/humanize/number.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
from .i18n import _ngettext_noop as NS_
1010
from .i18n import _pgettext as P_
1111

12+
13+
TYPE_CHECKING = False
14+
if TYPE_CHECKING:
15+
from typing import TypeAlias
16+
17+
# This type can be better defined by typing.SupportsFloat
18+
# but that's a Python 3.8 only typing option.
19+
NumberOrString: TypeAlias = float | str
20+
21+
1222
_SUPERSCRIPT_MAP = {
1323
"0": "⁰",
1424
"1": "¹",
@@ -23,14 +33,6 @@
2333
"-": "⁻",
2434
}
2535

26-
TYPE_CHECKING = False
27-
if TYPE_CHECKING:
28-
from typing import TypeAlias
29-
30-
# This type can be better defined by typing.SupportsFloat
31-
# but that's a Python 3.8 only typing option.
32-
NumberOrString: TypeAlias = float | str
33-
3436

3537
def _format_not_finite(value: float) -> str:
3638
"""Utility function to handle infinite and nan cases."""
@@ -442,8 +444,8 @@ def scientific(value: NumberOrString, precision: int = 2) -> str:
442444
import re
443445

444446
part2 = re.sub(r"^\+?(\-?)0*(.+)$", r"\1\2", part2)
447+
return part1 + " x 10" + "".join([_SUPERSCRIPT_MAP[char] for char in part2])
445448

446-
return part1 + " x 10" + "".join(_SUPERSCRIPT_MAP[char] for char in part2)
447449

448450

449451
def clamp(

0 commit comments

Comments
 (0)