summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAarni Koskela <akx@iki.fi>2023-01-18 20:01:03 +0200
committerAarni Koskela <akx@iki.fi>2023-01-18 21:07:51 +0200
commitf5ef6d06f961865ff9dbb3ff9d3fc81f0bbe8fd1 (patch)
tree0b43f15be5d02b3b8bb3691884f6d4011ed26e25
parent4cc26402e846733201d3d283d70deec394000dd0 (diff)
downloadbabel-f5ef6d06f961865ff9dbb3ff9d3fc81f0bbe8fd1.tar.gz
Apply ruff B category fixes
-rw-r--r--babel/core.py10
-rw-r--r--babel/dates.py2
-rw-r--r--babel/messages/checkers.py2
-rw-r--r--babel/messages/frontend.py5
-rw-r--r--babel/messages/jslexer.py2
-rw-r--r--babel/messages/mofile.py2
-rw-r--r--babel/numbers.py14
-rw-r--r--babel/plural.py2
-rw-r--r--babel/support.py4
-rw-r--r--pyproject.toml4
10 files changed, 26 insertions, 21 deletions
diff --git a/babel/core.py b/babel/core.py
index 5041c1b..604e5d9 100644
--- a/babel/core.py
+++ b/babel/core.py
@@ -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)
diff --git a/babel/dates.py b/babel/dates.py
index 51bc7ff..0f08437 100644
--- a/babel/dates.py
+++ b/babel/dates.py
@@ -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]:
diff --git a/babel/messages/checkers.py b/babel/messages/checkers.py
index 00b84e5..5e36b87 100644
--- a/babel/messages/checkers.py
+++ b/babel/messages/checkers.py
@@ -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:
diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py
index a18d00d..a9a3e4d 100644
--- a/babel/messages/frontend.py
+++ b/babel/messages/frontend.py
@@ -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())
diff --git a/babel/messages/jslexer.py b/babel/messages/jslexer.py
index 07fffde..0c7630c 100644
--- a/babel/messages/jslexer.py
+++ b/babel/messages/jslexer.py
@@ -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
diff --git a/babel/messages/mofile.py b/babel/messages/mofile.py
index a96f059..0a432a7 100644
--- a/babel/messages/mofile.py
+++ b/babel/messages/mofile.py
@@ -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])
diff --git a/babel/numbers.py b/babel/numbers.py
index 5a05f91..f229072 100644
--- a/babel/numbers.py
+++ b/babel/numbers.py
@@ -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:
diff --git a/babel/plural.py b/babel/plural.py
index b4f54c0..62bb020 100644
--- a/babel/plural.py
+++ b/babel/plural.py
@@ -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 = []
diff --git a/babel/support.py b/babel/support.py
index a8dd230..d457d79 100644
--- a/babel/support.py
+++ b/babel/support.py
@@ -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)
)
diff --git a/pyproject.toml b/pyproject.toml
index 977d84b..aeee570 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,8 @@
[tool.ruff]
target-version = "py37"
-select = []
+select = [
+ "B",
+]
ignore = [
"C901", # Complexity
"E501", # Line length