Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
akx authored Nov 28, 2023
1 parent 648bddb commit 9032583
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
12 changes: 8 additions & 4 deletions babel/numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def _get_numbering_system(locale: Locale, numbering_system: Literal["default"] |


def _get_number_symbols(
locale: Locale | str,
locale: Locale | str | None,
*,
numbering_system: Literal["default"] | str = "latn",
) -> LocaleDataDict:
Expand Down Expand Up @@ -1275,6 +1275,7 @@ def scientific_notation_elements(
self,
value: decimal.Decimal,
locale: Locale | str | None,
*,
numbering_system: str,
) -> tuple[decimal.Decimal, int, str]:
""" Returns normalized scientific notation components of a value.
Expand Down Expand Up @@ -1458,7 +1459,7 @@ def _format_significant(self, value: decimal.Decimal, minimum: int, maximum: int
).rstrip('.')
return result

def _format_int(self, value: str, min: int, max: int, locale: Locale | str | None, numbering_system: str) -> str:
def _format_int(self, value: str, min: int, max: int, locale: Locale | str | None, *, numbering_system: str) -> str:
width = len(value)
if width < min:
value = '0' * (min - width) + value
Expand All @@ -1475,7 +1476,9 @@ def _quantize_value(
self,
value: decimal.Decimal,
locale: Locale | str | None,
frac_prec: tuple[int, int], group_separator: bool,
frac_prec: tuple[int, int],
group_separator: bool,
*,
numbering_system: str,
) -> str:
# If the number is +/-Infinity, we can't quantize it
Expand All @@ -1493,9 +1496,10 @@ def _quantize_value(
def _format_frac(
self,
value: str,
numbering_system: str,
locale: Locale | str | None,
force_frac: tuple[int, int] | None = None,
*,
numbering_system: str,
) -> str:
min, max = force_frac or self.frac_prec
if len(value) < min:
Expand Down
2 changes: 1 addition & 1 deletion babel/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(
self,
locale: Locale | str,
tzinfo: datetime.tzinfo | None = None,
*,
numbering_system: Literal["default"] | str = "latn",
) -> None:
"""Initialize the formatter.
Expand All @@ -61,7 +62,6 @@ def __init__(
:param tzinfo: the time-zone info (a `tzinfo` instance or `None`)
:param numbering_system: The numbering system used for formatting number symbols. Defaults to "latn".
The special value "default" will use the default numbering system of the locale.
:raise `UnsupportedNumberingSystemError`: If the numbering system is not supported by the locale.
"""
self.locale = Locale.parse(locale)
self.tzinfo = tzinfo
Expand Down
2 changes: 1 addition & 1 deletion babel/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def format_compound_unit(
>>> format_compound_unit(32.5, "ton", 15, denominator_unit="hour", locale="en")
'32.5 tons per 15 hours'
>>> format_compound_unit(1234.5, "ton", 15, denominator_unit="hour", locale="ar_EG", numbering_system="default")
>>> format_compound_unit(1234.5, "ton", 15, denominator_unit="hour", locale="ar_EG", numbering_system="arab")
'1٬234٫5 طن لكل 15 ساعة'
>>> format_compound_unit(160, denominator_unit="square-meter", locale="fr")
Expand Down
4 changes: 0 additions & 4 deletions tests/test_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,6 @@ def test_format_decimal():
with pytest.raises(numbers.UnsupportedNumberingSystemError):
numbers.format_decimal(12345.5, locale='en_US', numbering_system="unknown")




@pytest.mark.parametrize('input_value, expected_value', [
('10000', '10,000'),
('1', '1'),
Expand Down Expand Up @@ -742,7 +739,6 @@ def test_parse_number():
with pytest.raises(numbers.UnsupportedNumberingSystemError):
numbers.parse_number('1.099,98', locale='en', numbering_system="unsupported")


def test_parse_decimal():
assert (numbers.parse_decimal('1,099.98', locale='en_US')
== decimal.Decimal('1099.98'))
Expand Down

0 comments on commit 9032583

Please sign in to comment.