]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Apply ruff B category fixes
authorAarni Koskela <akx@iki.fi>
Wed, 18 Jan 2023 18:01:03 +0000 (20:01 +0200)
committerAarni Koskela <akx@iki.fi>
Wed, 18 Jan 2023 19:07:51 +0000 (21:07 +0200)
babel/core.py
babel/dates.py
babel/messages/checkers.py
babel/messages/frontend.py
babel/messages/jslexer.py
babel/messages/mofile.py
babel/numbers.py
babel/plural.py
babel/support.py
pyproject.toml

index 5041c1bb920094f761bb5f99751dec05af34a6df..604e5d9ee25978602e11a881f8fbceeb3fba40d3 100644 (file)
@@ -383,10 +383,12 @@ class Locale:
         for key in ('language', 'territory', 'script', 'variant'):
             if not hasattr(other, key):
                 return False
-        return (self.language == getattr(other, 'language')) and \
-            (self.territory == getattr(other, 'territory')) and \
-            (self.script == getattr(other, 'script')) and \
-            (self.variant == getattr(other, 'variant'))
+        return (
+            self.language == getattr(other, 'language') and  # noqa: B009
+            self.territory == getattr(other, 'territory') and  # noqa: B009
+            self.script == getattr(other, 'script') and  # noqa: B009
+            self.variant == getattr(other, 'variant')  # noqa: B009
+        )
 
     def __ne__(self, other: object) -> bool:
         return not self.__eq__(other)
index 51bc7ffcf97b56dbc2cc761aef72f3d95ce6cd8c..0f08437669d3e3d0ee5186a1693cf317df903e40 100644 (file)
@@ -1884,7 +1884,7 @@ def tokenize_pattern(pattern: str) -> list[tuple[str, str | tuple[str, int]]]:
         fieldchar[0] = ''
         fieldnum[0] = 0
 
-    for idx, char in enumerate(pattern.replace("''", '\0')):
+    for char in pattern.replace("''", '\0'):
         if quotebuf is None:
             if char == "'":  # quote started
                 if fieldchar[0]:
index 00b84e5e3082537d01ce945c99b5fb72ef301be8..5e36b87f3e69a4e9605e9dc8c184a069f321fbab 100644 (file)
@@ -111,7 +111,7 @@ def _validate_format(format: str, alternative: str) -> None:
 
     def _check_positional(results: list[tuple[str, str]]) -> bool:
         positional = None
-        for name, char in results:
+        for name, _char in results:
             if positional is None:
                 positional = name is None
             else:
index a18d00d9fe916f4327a39260b2e801982eec70cf..a9a3e4d6a28be2e243146e503f07988ee2d00447 100644 (file)
@@ -20,6 +20,7 @@ from collections import OrderedDict
 from configparser import RawConfigParser
 import datetime
 from io import StringIO
+from typing import Iterable
 
 from babel import __version__ as VERSION
 from babel import Locale, localedata
@@ -188,7 +189,7 @@ class compile_catalog(Command):
     def run(self):
         n_errors = 0
         for domain in self.domain:
-            for catalog, errors in self._run_domain(domain).items():
+            for errors in self._run_domain(domain).values():
                 n_errors += len(errors)
         if n_errors:
             self.log.error('%d errors encountered.', n_errors)
@@ -1108,7 +1109,7 @@ def parse_mapping(fileobj, filename=None):
     return method_map, options_map
 
 
-def parse_keywords(strings=[]):
+def parse_keywords(strings: Iterable[str] = ()):
     """Parse keywords specifications from the given list of strings.
 
     >>> kw = sorted(parse_keywords(['_', 'dgettext:2', 'dngettext:2,3', 'pgettext:1c,2']).items())
index 07fffdec75f4b52fae77e1ffff52bf87746a852d..0c7630cfb1afefa784acbc44dc14fa1784b5f293 100644 (file)
@@ -174,7 +174,7 @@ def tokenize(source: str, jsx: bool = True, dotted: bool = True, template_string
 
     while pos < end:
         # handle regular rules first
-        for token_type, rule in rules:
+        for token_type, rule in rules:  # noqa: B007
             match = rule.match(source, pos)
             if match is not None:
                 break
index a96f0592b76480123ef3dd89e6c7d6dc61f879fe..0a432a792d3dd17fb5854b9bd4f385acea092b9b 100644 (file)
@@ -55,7 +55,7 @@ def read_mo(fileobj: SupportsRead[bytes]) -> Catalog:
 
     # Now put all messages from the .mo file buffer into the catalog
     # dictionary
-    for i in range(0, msgcount):
+    for _i in range(msgcount):
         mlen, moff = unpack(ii, buf[origidx:origidx + 8])
         mend = moff + mlen
         tlen, toff = unpack(ii, buf[transidx:transidx + 8])
index 5a05f910e11e4465ee1309364106e8a90443c076..f229072a86a0cde02021ea9ac6e08ff21bc67bbd 100644 (file)
@@ -653,7 +653,7 @@ def format_currency(
         try:
             pattern = locale.currency_formats[format_type]
         except KeyError:
-            raise UnknownCurrencyFormatError(f"{format_type!r} is not a known currency format type")
+            raise UnknownCurrencyFormatError(f"{format_type!r} is not a known currency format type") from None
 
     return pattern.apply(
         number, locale, currency=currency, currency_digits=currency_digits,
@@ -870,8 +870,8 @@ def parse_number(string: str, locale: Locale | str | None = LC_NUMERIC) -> int:
     """
     try:
         return int(string.replace(get_group_symbol(locale), ''))
-    except ValueError:
-        raise NumberFormatError(f"{string!r} is not a valid number")
+    except ValueError as ve:
+        raise NumberFormatError(f"{string!r} is not a valid number") from ve
 
 
 def parse_decimal(string: str, locale: Locale | str | None = LC_NUMERIC, strict: bool = False) -> decimal.Decimal:
@@ -926,20 +926,20 @@ def parse_decimal(string: str, locale: Locale | str | None = LC_NUMERIC, strict:
     try:
         parsed = decimal.Decimal(string.replace(group_symbol, '')
                                        .replace(decimal_symbol, '.'))
-    except decimal.InvalidOperation:
-        raise NumberFormatError(f"{string!r} is not a valid decimal number")
+    except decimal.InvalidOperation as exc:
+        raise NumberFormatError(f"{string!r} is not a valid decimal number") from exc
     if strict and group_symbol in string:
         proper = format_decimal(parsed, locale=locale, decimal_quantization=False)
         if string != proper and string.rstrip('0') != (proper + decimal_symbol):
             try:
                 parsed_alt = decimal.Decimal(string.replace(decimal_symbol, '')
                                                    .replace(group_symbol, '.'))
-            except decimal.InvalidOperation:
+            except decimal.InvalidOperation as exc:
                 raise NumberFormatError(
                     f"{string!r} is not a properly formatted decimal number. "
                     f"Did you mean {proper!r}?",
                     suggestions=[proper],
-                )
+                ) from exc
             else:
                 proper_alt = format_decimal(parsed_alt, locale=locale, decimal_quantization=False)
                 if proper_alt == proper:
index b4f54c018287de34877e57c7f683972ac3b77fc4..62bb02078b73763d1894ff6839aed8d02583d587 100644 (file)
@@ -627,7 +627,7 @@ class _UnicodeCompiler(_Compiler):
     compile_mod = _binary_compiler('%s mod %s')
 
     def compile_not(self, relation):
-        return self.compile_relation(negated=True, *relation[1])
+        return self.compile_relation(*relation[1], negated=True)
 
     def compile_relation(self, method, expr, range_list, negated=False):
         ranges = []
index a8dd2305d5afacf45971df4dde3e1df2eaa015a9..d457d796c3095b745e2e7d9e21ecbdb488d4a60a 100644 (file)
@@ -333,7 +333,7 @@ class LazyProxy:
         return LazyProxy(
             self._func,
             enable_cache=self._is_cache_enabled,
-            *self._args,
+            *self._args,  # noqa: B026
             **self._kwargs
         )
 
@@ -342,7 +342,7 @@ class LazyProxy:
         return LazyProxy(
             deepcopy(self._func, memo),
             enable_cache=deepcopy(self._is_cache_enabled, memo),
-            *deepcopy(self._args, memo),
+            *deepcopy(self._args, memo),  # noqa: B026
             **deepcopy(self._kwargs, memo)
         )
 
index 977d84b6612aa6aa5f3242b0592217e3a9c1c254..aeee57024c30483eb161c6717ae5effe970f0ea0 100644 (file)
@@ -1,6 +1,8 @@
 [tool.ruff]
 target-version = "py37"
-select = []
+select = [
+    "B",
+]
 ignore = [
     "C901",  # Complexity
     "E501",  # Line length