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)
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]:
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:
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
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)
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())
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
# 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])
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,
"""
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:
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:
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 = []
return LazyProxy(
self._func,
enable_cache=self._is_cache_enabled,
- *self._args,
+ *self._args, # noqa: B026
**self._kwargs
)
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)
)
[tool.ruff]
target-version = "py37"
-select = []
+select = [
+ "B",
+]
ignore = [
"C901", # Complexity
"E501", # Line length