Skip to content

Commit 5f10d90

Browse files
committed
style: formatting
1 parent 298a8c1 commit 5f10d90

5 files changed

Lines changed: 26 additions & 28 deletions

File tree

babel/dates.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
from typing_extensions import Literal, TypeAlias
3535

3636
_Instant: TypeAlias = date | time | float | None
37-
_PredefinedTimeFormat: TypeAlias = Literal["full", "long", "medium", "short"]
38-
_Context: TypeAlias = Literal["format", "stand-alone"]
37+
_PredefinedTimeFormat: TypeAlias = Literal['full', 'long', 'medium', 'short']
38+
_Context: TypeAlias = Literal['format', 'stand-alone']
3939
_DtOrTzinfo: TypeAlias = datetime | tzinfo | str | int | time | None
4040

4141
# "If a given short metazone form is known NOT to be understood in a given
@@ -327,7 +327,7 @@ def __repr__(self) -> str:
327327
return f"<TimezoneTransition {self.from_tz} -> {self.to_tz} ({self.activates})>"
328328

329329

330-
def get_period_names(width: Literal["abbreviated", "narrow", "wide"] = 'wide',
330+
def get_period_names(width: Literal['abbreviated', 'narrow', 'wide'] = 'wide',
331331
context: _Context = 'stand-alone', locale: Locale | str | None = LC_TIME) -> LocaleDataDict:
332332
"""Return the names for day periods (AM/PM) used by the locale.
333333
@@ -341,7 +341,7 @@ def get_period_names(width: Literal["abbreviated", "narrow", "wide"] = 'wide',
341341
return Locale.parse(locale).day_periods[context][width]
342342

343343

344-
def get_day_names(width: Literal["abbreviated", "narrow", "short", "wide"] = 'wide',
344+
def get_day_names(width: Literal['abbreviated', 'narrow', 'short', 'wide'] = 'wide',
345345
context: _Context = 'format', locale: Locale | str | None = LC_TIME) -> LocaleDataDict:
346346
"""Return the day names used by the locale for the specified format.
347347
@@ -361,7 +361,7 @@ def get_day_names(width: Literal["abbreviated", "narrow", "short", "wide"] = 'wi
361361
return Locale.parse(locale).days[context][width]
362362

363363

364-
def get_month_names(width: Literal["abbreviated", "narrow", "wide"] = 'wide',
364+
def get_month_names(width: Literal['abbreviated', 'narrow', 'wide'] = 'wide',
365365
context: _Context = 'format', locale: Locale | str | None = LC_TIME) -> LocaleDataDict:
366366
"""Return the month names used by the locale for the specified format.
367367
@@ -379,7 +379,7 @@ def get_month_names(width: Literal["abbreviated", "narrow", "wide"] = 'wide',
379379
return Locale.parse(locale).months[context][width]
380380

381381

382-
def get_quarter_names(width: Literal["abbreviated", "narrow", "wide"] = 'wide',
382+
def get_quarter_names(width: Literal['abbreviated', 'narrow', 'wide'] = 'wide',
383383
context: _Context = 'format', locale: Locale | str | None = LC_TIME) -> LocaleDataDict:
384384
"""Return the quarter names used by the locale for the specified format.
385385
@@ -397,7 +397,7 @@ def get_quarter_names(width: Literal["abbreviated", "narrow", "wide"] = 'wide',
397397
return Locale.parse(locale).quarters[context][width]
398398

399399

400-
def get_era_names(width: Literal["abbreviated", "narrow", "wide"] = 'wide',
400+
def get_era_names(width: Literal['abbreviated', 'narrow', 'wide'] = 'wide',
401401
locale: Locale | str | None = LC_TIME) -> LocaleDataDict:
402402
"""Return the era names used by the locale for the specified format.
403403
@@ -461,7 +461,7 @@ def get_time_format(format: _PredefinedTimeFormat = 'medium', locale: Locale | s
461461
return Locale.parse(locale).time_formats[format]
462462

463463

464-
def get_timezone_gmt(datetime: _Instant = None, width: Literal["long", "short", "iso8601", "iso8601_short"] = 'long',
464+
def get_timezone_gmt(datetime: _Instant = None, width: Literal['long', 'short', 'iso8601', 'iso8601_short'] = 'long',
465465
locale: Locale | str | None = LC_TIME, return_z: bool = False) -> str:
466466
"""Return the timezone associated with the given `datetime` object formatted
467467
as string indicating the offset from GMT.
@@ -593,8 +593,8 @@ def get_timezone_location(dt_or_tzinfo: _DtOrTzinfo = None, locale: Locale | str
593593
})
594594

595595

596-
def get_timezone_name(dt_or_tzinfo: _DtOrTzinfo = None, width: Literal["long", "short"] = 'long', uncommon: bool = False,
597-
locale: Locale | str | None = LC_TIME, zone_variant: Literal["generic", "daylight", "standard"] | None = None,
596+
def get_timezone_name(dt_or_tzinfo: _DtOrTzinfo = None, width: Literal['long', 'short'] = 'long', uncommon: bool = False,
597+
locale: Locale | str | None = LC_TIME, zone_variant: Literal['generic', 'daylight', 'standard'] | None = None,
598598
return_zone: bool = False) -> str:
599599
r"""Return the localized display name for the given timezone. The timezone
600600
may be specified using a ``datetime`` or `tzinfo` object.
@@ -900,8 +900,8 @@ def format_skeleton(skeleton: str, datetime: _Instant = None, tzinfo: tzinfo | N
900900

901901

902902
def format_timedelta(delta: timedelta | int,
903-
granularity: Literal["year", "month", "week", "day", "hour", "minute", "second"] = 'second',
904-
threshold: float = .85, add_direction: bool = False, format: Literal["narrow", "short", "medium", "long"] = 'long',
903+
granularity: Literal['year', 'month', 'week', 'day', 'hour', 'minute', 'second'] = 'second',
904+
threshold: float = .85, add_direction: bool = False, format: Literal['narrow', 'short', 'medium', 'long'] = 'long',
905905
locale: Locale | str | None = LC_TIME) -> str:
906906
"""Return a time delta according to the rules of the given locale.
907907
@@ -1124,7 +1124,7 @@ def format_interval(start: _Instant, end: _Instant, skeleton: str | None = None,
11241124
return _format_fallback_interval(start, end, skeleton, tzinfo, locale)
11251125

11261126

1127-
def get_period_id(time: _Instant, tzinfo: _pytz.BaseTzInfo | None = None, type: Literal["selection"] | None = None,
1127+
def get_period_id(time: _Instant, tzinfo: _pytz.BaseTzInfo | None = None, type: Literal['selection'] | None = None,
11281128
locale: Locale | str | None = LC_TIME) -> str:
11291129
"""
11301130
Get the day period ID for a given time.

babel/lists.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828

2929
def format_list(lst: Sequence[str],
30-
style: Literal["standard", "standard-short", "or", "or-short", "unit", "unit-short", "unit-narrow"] = 'standard',
30+
style: Literal['standard', 'standard-short', 'or', 'or-short', 'unit', 'unit-short', 'unit-narrow'] = 'standard',
3131
locale: Locale | str | None = DEFAULT_LOCALE) -> str:
3232
"""
3333
Format the items in `lst` as a list.

babel/numbers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ def format_decimal(
427427
number, locale, decimal_quantization=decimal_quantization, group_separator=group_separator)
428428

429429

430-
def format_compact_decimal(number: float | decimal.Decimal | str, *, format_type: Literal["short", "long"] = "short",
430+
def format_compact_decimal(number: float | decimal.Decimal | str, *, format_type: Literal['short', 'long'] = 'short',
431431
locale: Locale | str | None = LC_NUMERIC, fraction_digits: int = 0) -> str:
432432
u"""Return the given decimal number formatted for a specific locale in compact form.
433433
@@ -496,7 +496,7 @@ class UnknownCurrencyFormatError(KeyError):
496496
def format_currency(
497497
number: float | decimal.Decimal | str, currency: str, format: str | None = None,
498498
locale: Locale | str | None = LC_NUMERIC, currency_digits: bool = True,
499-
format_type: Literal["name", "standard", "accounting"] = 'standard',
499+
format_type: Literal['name', 'standard', 'accounting'] = 'standard',
500500
decimal_quantization: bool = True, group_separator: bool = True) -> str:
501501
u"""Return formatted currency value.
502502
@@ -606,7 +606,7 @@ def format_currency(
606606
def _format_currency_long_name(
607607
number: float | decimal.Decimal | str, currency: str, format: str | None = None,
608608
locale: Locale | str | None = LC_NUMERIC, currency_digits: bool = True,
609-
format_type: Literal["name", "standard", "accounting"] = 'standard',
609+
format_type: Literal['name', 'standard', 'accounting'] = 'standard',
610610
decimal_quantization: bool = True, group_separator: bool = True) -> str:
611611
# Algorithm described here:
612612
# https://www.unicode.org/reports/tr35/tr35-numbers.html#Currencies
@@ -642,7 +642,7 @@ def _format_currency_long_name(
642642

643643

644644
def format_compact_currency(number: float | decimal.Decimal | str,
645-
currency: str, *, format_type: Literal["short"] = "short",
645+
currency: str, *, format_type: Literal['short'] = 'short',
646646
locale: Locale | str | None = LC_NUMERIC, fraction_digits: int = 0) -> str:
647647
u"""Format a number as a currency value in compact form.
648648

babel/support.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ def time(self, time: _time | _datetime | None = None, format: _PredefinedTimeFor
9090
return format_time(time, format, tzinfo=self.tzinfo, locale=self.locale)
9191

9292
def timedelta(self, delta: _timedelta | int,
93-
granularity: Literal["year", "month", "week", "day", "hour", "minute", "second"] = 'second',
94-
threshold: float = .85, format: Literal["narrow", "short", "medium", "long"] = 'long',
93+
granularity: Literal['year', 'month', 'week', 'day', 'hour', 'minute', 'second'] = 'second',
94+
threshold: float = .85, format: Literal['narrow', 'short', 'medium', 'long'] = 'long',
9595
add_direction: bool = False) -> str:
9696
"""Return a time delta according to the rules of the given locale.
9797
@@ -124,7 +124,7 @@ def decimal(self, number: float | decimal.Decimal | str, format: str | None = No
124124
return format_decimal(number, format, locale=self.locale)
125125

126126
def compact_decimal(self, number: float | decimal.Decimal | str,
127-
format_type: Literal["short", "long"] = 'short', fraction_digits: int = 0) -> str:
127+
format_type: Literal['short', 'long'] = 'short', fraction_digits: int = 0) -> str:
128128
"""Return a number formatted in compact form for the locale.
129129
130130
>>> fmt = Format('en_US')
@@ -141,7 +141,7 @@ def currency(self, number: float | decimal.Decimal | str, currency: str) -> str:
141141
return format_currency(number, currency, locale=self.locale)
142142

143143
def compact_currency(self, number: float | decimal.Decimal | str, currency: str,
144-
format_type: Literal["short"] = 'short', fraction_digits: int = 0) -> str:
144+
format_type: Literal['short'] = 'short', fraction_digits: int = 0) -> str:
145145
"""Return a number in the given currency formatted for the locale
146146
using the compact number format.
147147
"""
@@ -431,9 +431,7 @@ def lpgettext(self, context: str, message: str) -> str | bytes | object:
431431
DeprecationWarning, 2)
432432
tmsg = self.pgettext(context, message)
433433
encoding = getattr(self, "_output_charset", None) or locale.getpreferredencoding()
434-
if not isinstance(tmsg, str):
435-
return tmsg
436-
return tmsg.encode(encoding)
434+
return tmsg.encode(encoding) if isinstance(tmsg, str) else tmsg
437435

438436
def npgettext(self, context: str, singular: str, plural: str, num: int) -> str:
439437
"""Do a plural-forms lookup of a message id. `singular` is used as the

babel/units.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __init__(self, unit: str, locale: Locale):
1414
ValueError.__init__(self, f"{unit} is not a known unit in {locale}")
1515

1616

17-
def get_unit_name(measurement_unit: str, length: Literal["short", "long", "narrow"] = 'long',
17+
def get_unit_name(measurement_unit: str, length: Literal['short', 'long', 'narrow'] = 'long',
1818
locale: Locale | str | None = LC_NUMERIC) -> str | None:
1919
"""
2020
Get the display name for a measurement unit in the given locale.
@@ -71,7 +71,7 @@ def _find_unit_pattern(unit_id: str, locale: Locale | str | None = LC_NUMERIC) -
7171

7272

7373
def format_unit(value: float | decimal.Decimal, measurement_unit: str,
74-
length: Literal["short", "long", "narrow"] = 'long', format: str | None = None,
74+
length: Literal['short', 'long', 'narrow'] = 'long', format: str | None = None,
7575
locale: Locale | str | None = LC_NUMERIC) -> str:
7676
"""Format a value of a given unit.
7777
@@ -193,7 +193,7 @@ def _find_compound_unit(numerator_unit: str, denominator_unit: str, locale: Loca
193193
def format_compound_unit(
194194
numerator_value: float | decimal.Decimal, numerator_unit: str | None = None,
195195
denominator_value: float | decimal.Decimal = 1, denominator_unit: str | None = None,
196-
length: Literal["short", "long", "narrow"] = 'long', format: str | None = None,
196+
length: Literal['short', 'long', 'narrow'] = 'long', format: str | None = None,
197197
locale: Locale | str | None = LC_NUMERIC) -> str | None:
198198
"""
199199
Format a compound number value, i.e. "kilometers per hour" or similar.

0 commit comments

Comments
 (0)