Skip to content

Commit

Permalink
style: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
DenverCoder1 committed Dec 5, 2022
1 parent 298a8c1 commit 5f10d90
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 28 deletions.
26 changes: 13 additions & 13 deletions babel/dates.py
Expand Up @@ -34,8 +34,8 @@
from typing_extensions import Literal, TypeAlias

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

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


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


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


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


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


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


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


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


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


def get_period_id(time: _Instant, tzinfo: _pytz.BaseTzInfo | None = None, type: Literal["selection"] | None = None,
def get_period_id(time: _Instant, tzinfo: _pytz.BaseTzInfo | None = None, type: Literal['selection'] | None = None,
locale: Locale | str | None = LC_TIME) -> str:
"""
Get the day period ID for a given time.
Expand Down
2 changes: 1 addition & 1 deletion babel/lists.py
Expand Up @@ -27,7 +27,7 @@


def format_list(lst: Sequence[str],
style: Literal["standard", "standard-short", "or", "or-short", "unit", "unit-short", "unit-narrow"] = 'standard',
style: Literal['standard', 'standard-short', 'or', 'or-short', 'unit', 'unit-short', 'unit-narrow'] = 'standard',
locale: Locale | str | None = DEFAULT_LOCALE) -> str:
"""
Format the items in `lst` as a list.
Expand Down
8 changes: 4 additions & 4 deletions babel/numbers.py
Expand Up @@ -427,7 +427,7 @@ def format_decimal(
number, locale, decimal_quantization=decimal_quantization, group_separator=group_separator)


def format_compact_decimal(number: float | decimal.Decimal | str, *, format_type: Literal["short", "long"] = "short",
def format_compact_decimal(number: float | decimal.Decimal | str, *, format_type: Literal['short', 'long'] = 'short',
locale: Locale | str | None = LC_NUMERIC, fraction_digits: int = 0) -> str:
u"""Return the given decimal number formatted for a specific locale in compact form.
Expand Down Expand Up @@ -496,7 +496,7 @@ class UnknownCurrencyFormatError(KeyError):
def format_currency(
number: float | decimal.Decimal | str, currency: str, format: str | None = None,
locale: Locale | str | None = LC_NUMERIC, currency_digits: bool = True,
format_type: Literal["name", "standard", "accounting"] = 'standard',
format_type: Literal['name', 'standard', 'accounting'] = 'standard',
decimal_quantization: bool = True, group_separator: bool = True) -> str:
u"""Return formatted currency value.
Expand Down Expand Up @@ -606,7 +606,7 @@ def format_currency(
def _format_currency_long_name(
number: float | decimal.Decimal | str, currency: str, format: str | None = None,
locale: Locale | str | None = LC_NUMERIC, currency_digits: bool = True,
format_type: Literal["name", "standard", "accounting"] = 'standard',
format_type: Literal['name', 'standard', 'accounting'] = 'standard',
decimal_quantization: bool = True, group_separator: bool = True) -> str:
# Algorithm described here:
# https://www.unicode.org/reports/tr35/tr35-numbers.html#Currencies
Expand Down Expand Up @@ -642,7 +642,7 @@ def _format_currency_long_name(


def format_compact_currency(number: float | decimal.Decimal | str,
currency: str, *, format_type: Literal["short"] = "short",
currency: str, *, format_type: Literal['short'] = 'short',
locale: Locale | str | None = LC_NUMERIC, fraction_digits: int = 0) -> str:
u"""Format a number as a currency value in compact form.
Expand Down
12 changes: 5 additions & 7 deletions babel/support.py
Expand Up @@ -90,8 +90,8 @@ def time(self, time: _time | _datetime | None = None, format: _PredefinedTimeFor
return format_time(time, format, tzinfo=self.tzinfo, locale=self.locale)

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

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

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

def npgettext(self, context: str, singular: str, plural: str, num: int) -> str:
"""Do a plural-forms lookup of a message id. `singular` is used as the
Expand Down
6 changes: 3 additions & 3 deletions babel/units.py
Expand Up @@ -14,7 +14,7 @@ def __init__(self, unit: str, locale: Locale):
ValueError.__init__(self, f"{unit} is not a known unit in {locale}")


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


def format_unit(value: float | decimal.Decimal, measurement_unit: str,
length: Literal["short", "long", "narrow"] = 'long', format: str | None = None,
length: Literal['short', 'long', 'narrow'] = 'long', format: str | None = None,
locale: Locale | str | None = LC_NUMERIC) -> str:
"""Format a value of a given unit.
Expand Down Expand Up @@ -193,7 +193,7 @@ def _find_compound_unit(numerator_unit: str, denominator_unit: str, locale: Loca
def format_compound_unit(
numerator_value: float | decimal.Decimal, numerator_unit: str | None = None,
denominator_value: float | decimal.Decimal = 1, denominator_unit: str | None = None,
length: Literal["short", "long", "narrow"] = 'long', format: str | None = None,
length: Literal['short', 'long', 'narrow'] = 'long', format: str | None = None,
locale: Locale | str | None = LC_NUMERIC) -> str | None:
"""
Format a compound number value, i.e. "kilometers per hour" or similar.
Expand Down

0 comments on commit 5f10d90

Please sign in to comment.