8000 Apply suggestions from code review · python-babel/babel@abe6bda · GitHub
[go: up one dir, main page]

Skip to content

Commit abe6bda

Browse files
committed
Apply suggestions from code review
1 parent 648bddb commit abe6bda

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

babel/numbers.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def _get_numbering_system(locale: Locale, numbering_system: Literal["default"] |
325325

326326

327327
def _get_number_symbols(
328-
locale: Locale | str,
328+
locale: Locale | str | None,
329329
*,
330330
numbering_system: Literal["default"] | str = "latn",
331331
) -> LocaleDataDict:
@@ -1275,7 +1275,8 @@ def scientific_notation_elements(
12751275
self,
12761276
value: decimal.Decimal,
12771277
locale: Locale | str | None,
1278-
numbering_system: str,
1278+
*,
1279+
numbering_system: Literal["default"] | str = "latn",
12791280
) -> tuple[decimal.Decimal, int, str]:
12801281
""" Returns normalized scientific notation components of a value.
12811282
"""
@@ -1337,8 +1338,8 @@ def apply(
13371338
:type decimal_quantization: bool
13381339
:param force_frac: DEPRECATED - a forced override for `self.frac_prec`
13391340
for a single formatting invocation.
1340-
:param numbering_system: The numbering system used for formatting number symbols. Defaults to "latn", special
1341-
value "default" will use the default numbering system of the locale.
1341+
:param numbering_system: The numbering system used for formatting number symbols. Defaults to "latn".
1342+
The special value "default" will use the default numbering system of the locale.
13421343
:return: Formatted decimal string.
13431344
:rtype: str
13441345
:raise UnsupportedNumberingSystemError: If the numbering system is not supported by the locale.
@@ -1458,7 +1459,15 @@ def _format_significant(self, value: decimal.Decimal, minimum: int, maximum: int
14581459
).rstrip('.')
14591460
return result
14601461

1461-
def _format_int(self, value: str, min: int, max: int, locale: Locale | str | None, numbering_system: str) -> str:
1462+
def _format_int(
1463+
self,
1464+
value: str,
1465+
min: int,
1466+
max: int,
1467+
locale: Locale | str | None,
1468+
*,
1469+
numbering_system: Literal["default"] | str,
1470+
) -> str:
14621471
width = len(value)
14631472
if width < min:
14641473
value = '0' * (min - width) + value
@@ -1475,8 +1484,10 @@ def _quantize_value(
14751484
self,
14761485
value: decimal.Decimal,
14771486
locale: Locale | str | None,
1478-
frac_prec: tuple[int, int], group_separator: bool,
1479-
numbering_system: str,
1487+
frac_prec: tuple[int, int],
1488+
group_separator: bool,
1489+
*,
1490+
numbering_system: Literal["default"] | str,
14801491
) -> str:
14811492
# If the number is +/-Infinity, we can't quantize it
14821493
if value.is_infinite():
@@ -1493,9 +1504,10 @@ def _quantize_value(
14931504
def _format_frac(
14941505
self,
14951506
value: str,
1496-
numbering_system: str,
14971507
locale: Locale | str | None,
14981508
force_frac: tuple[int, int] | None = None,
1509+
*,
1510+
numbering_system: Literal["default"] | str,
14991511
) -> str:
15001512
min, max = force_frac or self.frac_prec
15011513
if len(value) < min:

babel/support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def __init__(
5353
self,
5454
locale: Locale | str,
5555
tzinfo: datetime.tzinfo | None = None,
56+
*,
5657
numbering_system: Literal["default"] | str = "latn",
5758
) -> None:
5859
"""Initialize the formatter.
@@ -61,7 +62,6 @@ def __init__(
6162
:param tzinfo: the time-zone info (a `tzinfo` instance or `None`)
6263
:param numbering_system: The numbering system used for formatting number symbols. Defaults to "latn".
6364
The special value "default" will use the default numbering system of the locale.
64-
:raise `UnsupportedNumberingSystemError`: If the numbering system is not supported by the locale.
6565
"""
6666
self.locale = Locale.parse(locale)
6767
self.tzinfo = tzinfo

babel/units.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def format_compound_unit(
239239
>>> format_compound_unit(32.5, "ton", 15, denominator_unit="hour", locale="en")
240240
'32.5 tons per 15 hours'
241241
242-
>>> format_compound_unit(1234.5, "ton", 15, denominator_unit="hour", locale="ar_EG", numbering_system="default")
242+
>>> format_compound_unit(1234.5, "ton", 15, denominator_unit="hour", locale="ar_EG", numbering_system="arab")
243243
'1٬234٫5 طن لكل 15 ساعة'
244244
245245
>>> format_compound_unit(160, denominator_unit="square-meter", locale="fr")

tests/test_numbers.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,6 @@ def test_format_decimal():
412412
with pytest.raises(numbers.UnsupportedNumberingSystemError):
413413
numbers.format_decimal(12345.5, locale='en_US', numbering_system="unknown")
414414

415-
416-
417-
418415
@pytest.mark.parametrize('input_value, expected_value', [
419416
('10000', '10,000'),
420417
('1', '1'),
@@ -742,7 +739,6 @@ def test_parse_number():
742739
with pytest.raises(numbers.UnsupportedNumberingSystemError):
743740
numbers.parse_number('1.099,98', locale='en', numbering_system="unsupported")
744741

745-
746742
def test_parse_decimal():
747743
assert (numbers.parse_decimal('1,099.98', locale='en_US')
748744
== decimal.Decimal('1099.98'))

0 commit comments

Comments
 (0)
0