• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

localstack / localstack / 21765279428

06 Feb 2026 08:43PM UTC coverage: 73.535% (-13.3%) from 86.871%
21765279428

Pull #13716

github

web-flow
Merge 0f5988375 into 20cc1b384
Pull Request #13716: Events: improve Store IAM Statement typing

6 of 6 new or added lines in 1 file covered. (100.0%)

9920 existing lines in 273 files now uncovered.

56187 of 76409 relevant lines covered (73.53%)

0.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.87
/localstack-core/localstack/utils/numbers.py
1
from typing import Any
1✔
2

3

4
def format_number(number: float, decimals: int = 2):
1✔
5
    # Note: interestingly, f"{number:.3g}" seems to yield incorrect results in some cases.
6
    # The logic below seems to be the most stable/reliable.
7
    result = f"{number:.{decimals}f}"
1✔
8
    if "." in result:
1✔
9
        result = result.rstrip("0").rstrip(".")
1✔
10
    return result
1✔
11

12

13
def is_number(s: Any) -> bool:
1✔
14
    # booleans inherit from int
15
    #
16
    # >>> a.__class__.__mro__
17
    # (<class 'bool'>, <class 'int'>, <class 'object'>)
18
    if s is False or s is True:
1✔
19
        return False
1✔
20

21
    try:
1✔
22
        float(s)  # for int, long and float
1✔
23
        return True
1✔
24
    except (TypeError, ValueError):
1✔
25
        return False
1✔
26

27

28
def to_number(s: Any) -> int | float:
1✔
29
    """Cast the string representation of the given object to a number (int or float), or raise ValueError."""
UNCOV
30
    try:
×
UNCOV
31
        return int(str(s))
×
UNCOV
32
    except ValueError:
×
UNCOV
33
        return float(str(s))
×
34

35

36
def format_bytes(count: float, default: str = "n/a"):
1✔
37
    """Format a bytes number as a human-readable unit, e.g., 1.3GB or 21.53MB"""
38
    if not is_number(count):
1✔
39
        return default
1✔
40
    cnt = float(count)
1✔
41
    if cnt < 0:
1✔
42
        return default
1✔
43
    units = ("B", "KB", "MB", "GB", "TB")
1✔
44
    for unit in units:
1✔
45
        if cnt < 1000 or unit == units[-1]:
1✔
46
            # FIXME: will return '1e+03TB' for 1000TB
47
            return f"{format_number(cnt, decimals=3)}{unit}"
1✔
48
        cnt = cnt / 1000.0
1✔
49
    return count
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc