Skip to content

Commit

Permalink
Merge pull request #1017 from python-babel/renovate
Browse files Browse the repository at this point in the history
Renovate lint tools
  • Loading branch information
akx committed Jun 27, 2023
2 parents 7ef7300 + fe186e0 commit c30af80
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.247
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.275
hooks:
- id: ruff
args:
Expand Down
17 changes: 10 additions & 7 deletions babel/dates.py
Expand Up @@ -538,11 +538,11 @@ def get_timezone_name(
>>> from datetime import time
>>> dt = time(15, 30, tzinfo=get_timezone('America/Los_Angeles'))
>>> get_timezone_name(dt, locale='en_US')
>>> get_timezone_name(dt, locale='en_US') # doctest: +SKIP
u'Pacific Standard Time'
>>> get_timezone_name(dt, locale='en_US', return_zone=True)
'America/Los_Angeles'
>>> get_timezone_name(dt, width='short', locale='en_US')
>>> get_timezone_name(dt, width='short', locale='en_US') # doctest: +SKIP
u'PST'
If this function gets passed only a `tzinfo` object and no concrete
Expand Down Expand Up @@ -774,10 +774,10 @@ def format_time(
>>> t = time(15, 30)
>>> format_time(t, format='full', tzinfo=get_timezone('Europe/Paris'),
... locale='fr_FR')
... locale='fr_FR') # doctest: +SKIP
u'15:30:00 heure normale d\u2019Europe centrale'
>>> format_time(t, format='full', tzinfo=get_timezone('US/Eastern'),
... locale='en_US')
... locale='en_US') # doctest: +SKIP
u'3:30:00\u202fPM Eastern Standard Time'
:param time: the ``time`` or ``datetime`` object; if `None`, the current
Expand Down Expand Up @@ -922,9 +922,12 @@ def format_timedelta(
if format not in ('narrow', 'short', 'medium', 'long'):
raise TypeError('Format must be one of "narrow", "short" or "long"')
if format == 'medium':
warnings.warn('"medium" value for format param of format_timedelta'
' is deprecated. Use "long" instead',
category=DeprecationWarning)
warnings.warn(
'"medium" value for format param of format_timedelta'
' is deprecated. Use "long" instead',
category=DeprecationWarning,
stacklevel=2,
)
format = 'long'
if isinstance(delta, datetime.timedelta):
seconds = int((delta.days * 86400) + delta.seconds)
Expand Down
8 changes: 4 additions & 4 deletions babel/messages/checkers.py
Expand Up @@ -148,10 +148,10 @@ def _check_positional(results: list[tuple[str, str]]) -> bool:
if name not in type_map:
raise TranslationError(f'unknown named placeholder {name!r}')
elif not _compatible(typechar, type_map[name]):
raise TranslationError('incompatible format for '
'placeholder %r: '
'%r and %r are not compatible' %
(name, typechar, type_map[name]))
raise TranslationError(
f'incompatible format for placeholder {name!r}: '
f'{typechar!r} and {type_map[name]!r} are not compatible'
)


def _find_checkers() -> list[Callable[[Catalog | None, Message], object]]:
Expand Down
2 changes: 1 addition & 1 deletion babel/messages/plurals.py
Expand Up @@ -213,7 +213,7 @@ class _PluralTuple(tuple):
The number of plurals used by the locale.""")
plural_expr = property(itemgetter(1), doc="""
The plural expression used by the locale.""")
plural_forms = property(lambda x: 'nplurals=%s; plural=%s;' % x, doc="""
plural_forms = property(lambda x: 'nplurals={}; plural={};'.format(*x), doc="""
The plural expression used by the catalog or locale.""")

def __str__(self) -> str:
Expand Down
8 changes: 6 additions & 2 deletions babel/numbers.py
Expand Up @@ -400,7 +400,7 @@ def format_number(number: float | decimal.Decimal | str, locale: Locale | str |
"""
warnings.warn('Use babel.numbers.format_decimal() instead.', DeprecationWarning)
warnings.warn('Use babel.numbers.format_decimal() instead.', DeprecationWarning, stacklevel=2)
return format_decimal(number, locale=locale)


Expand Down Expand Up @@ -1190,7 +1190,11 @@ def apply(
# currency's if necessary.
if force_frac:
# TODO (3.x?): Remove this parameter
warnings.warn('The force_frac parameter to NumberPattern.apply() is deprecated.', DeprecationWarning)
warnings.warn(
'The force_frac parameter to NumberPattern.apply() is deprecated.',
DeprecationWarning,
stacklevel=2,
)
frac_prec = force_frac
elif currency and currency_digits:
frac_prec = (get_currency_precision(currency), ) * 2
Expand Down
28 changes: 20 additions & 8 deletions babel/support.py
Expand Up @@ -393,8 +393,11 @@ def ldgettext(self, domain: str, message: str) -> str:
domain.
"""
import warnings
warnings.warn('ldgettext() is deprecated, use dgettext() instead',
DeprecationWarning, 2)
warnings.warn(
'ldgettext() is deprecated, use dgettext() instead',
DeprecationWarning,
stacklevel=2,
)
return self._domains.get(domain, self).lgettext(message)

def udgettext(self, domain: str, message: str) -> str:
Expand All @@ -416,8 +419,11 @@ def ldngettext(self, domain: str, singular: str, plural: str, num: int) -> str:
domain.
"""
import warnings
warnings.warn('ldngettext() is deprecated, use dngettext() instead',
DeprecationWarning, 2)
warnings.warn(
'ldngettext() is deprecated, use dngettext() instead',
DeprecationWarning,
stacklevel=2,
)
return self._domains.get(domain, self).lngettext(singular, plural, num)

def udngettext(self, domain: str, singular: str, plural: str, num: int) -> str:
Expand Down Expand Up @@ -458,8 +464,11 @@ def lpgettext(self, context: str, message: str) -> str | bytes | object:
``bind_textdomain_codeset()``.
"""
import warnings
warnings.warn('lpgettext() is deprecated, use pgettext() instead',
DeprecationWarning, 2)
warnings.warn(
'lpgettext() is deprecated, use pgettext() instead',
DeprecationWarning,
stacklevel=2,
)
tmsg = self.pgettext(context, message)
encoding = getattr(self, "_output_charset", None) or locale.getpreferredencoding()
return tmsg.encode(encoding) if isinstance(tmsg, str) else tmsg
Expand Down Expand Up @@ -493,8 +502,11 @@ def lnpgettext(self, context: str, singular: str, plural: str, num: int) -> str
``bind_textdomain_codeset()``.
"""
import warnings
warnings.warn('lnpgettext() is deprecated, use npgettext() instead',
DeprecationWarning, 2)
warnings.warn(
'lnpgettext() is deprecated, use npgettext() instead',
DeprecationWarning,
stacklevel=2,
)
ctxt_msg_id = self.CONTEXT_ENCODING % (context, singular)
try:
tmsg = self._catalog[(ctxt_msg_id, self.plural(num))]
Expand Down
8 changes: 4 additions & 4 deletions scripts/import_cldr.py
Expand Up @@ -525,25 +525,25 @@ def parse_dates(data, tree, sup, regions, territory):
if _should_skip_elem(elem):
continue
territories = elem.attrib['territories'].split()
if territory in territories or any([r in territories for r in regions]):
if territory in territories or any(r in territories for r in regions):
week_data['min_days'] = int(elem.attrib['count'])
for elem in supelem.findall('firstDay'):
if _should_skip_elem(elem):
continue
territories = elem.attrib['territories'].split()
if territory in territories or any([r in territories for r in regions]):
if territory in territories or any(r in territories for r in regions):
week_data['first_day'] = weekdays[elem.attrib['day']]
for elem in supelem.findall('weekendStart'):
if _should_skip_elem(elem):
continue
territories = elem.attrib['territories'].split()
if territory in territories or any([r in territories for r in regions]):
if territory in territories or any(r in territories for r in regions):
week_data['weekend_start'] = weekdays[elem.attrib['day']]
for elem in supelem.findall('weekendEnd'):
if _should_skip_elem(elem):
continue
territories = elem.attrib['territories'].split()
if territory in territories or any([r in territories for r in regions]):
if territory in territories or any(r in territories for r in regions):
week_data['weekend_end'] = weekdays[elem.attrib['day']]
zone_formats = data.setdefault('zone_formats', {})
for elem in tree.findall('.//timeZoneNames/gmtFormat'):
Expand Down
2 changes: 1 addition & 1 deletion tests/messages/test_catalog.py
Expand Up @@ -455,7 +455,7 @@ def test_catalog_update():
assert len(cat) == 3

msg1 = cat['green']
msg1.string
assert not msg1.string
assert msg1.locations == [('main.py', 99)]

msg2 = cat['blue']
Expand Down
2 changes: 1 addition & 1 deletion tests/test_support.py
Expand Up @@ -291,7 +291,7 @@ def raise_attribute_error():

proxy = support.LazyProxy(raise_attribute_error)
with pytest.raises(AttributeError) as exception:
proxy.value
_ = proxy.value

assert str(exception.value) == 'message'

Expand Down

0 comments on commit c30af80

Please sign in to comment.