Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce trailing commas (enable Ruff COM rule and autofix) #1045

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions babel/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def get_global(key: _GLOBAL_KEY) -> Mapping[str, Any]:
'ja': 'ja_JP', 'km': 'km_KH', 'ko': 'ko_KR', 'lt': 'lt_LT', 'lv': 'lv_LV',
'mk': 'mk_MK', 'nl': 'nl_NL', 'nn': 'nn_NO', 'no': 'nb_NO', 'pl': 'pl_PL',
'pt': 'pt_PT', 'ro': 'ro_RO', 'ru': 'ru_RU', 'sk': 'sk_SK', 'sl': 'sl_SI',
'sv': 'sv_SE', 'th': 'th_TH', 'tr': 'tr_TR', 'uk': 'uk_UA'
'sv': 'sv_SE', 'th': 'th_TH', 'tr': 'tr_TR', 'uk': 'uk_UA',
}


Expand Down Expand Up @@ -1149,7 +1149,7 @@ def negotiate_locale(preferred: Iterable[str], available: Iterable[str], sep: st

def parse_locale(
identifier: str,
sep: str = '_'
sep: str = '_',
) -> tuple[str, str | None, str | None, str | None] | tuple[str, str | None, str | None, str | None, str | None]:
"""Parse a locale identifier into a tuple of the form ``(language,
territory, script, variant, modifier)``.
Expand Down
8 changes: 4 additions & 4 deletions babel/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ def get_timezone_location(
return city_name
return region_format % (fallback_format % {
'0': city_name,
'1': territory_name
'1': territory_name,
})


Expand Down Expand Up @@ -852,7 +852,7 @@ def format_skeleton(
('day', 3600 * 24),
('hour', 3600),
('minute', 60),
('second', 1)
('second', 1),
)


Expand Down Expand Up @@ -1324,7 +1324,7 @@ def __init__(
self,
value: datetime.date | datetime.time,
locale: Locale | str,
reference_date: datetime.date | None = None
reference_date: datetime.date | None = None,
) -> None:
assert isinstance(value, (datetime.date, datetime.datetime, datetime.time))
if isinstance(value, (datetime.datetime, datetime.time)) and value.tzinfo is None:
Expand Down Expand Up @@ -1663,7 +1663,7 @@ def get_week_number(self, day_of_period: int, day_of_week: int | None = None) ->
'm': [1, 2], # minute
's': [1, 2], 'S': None, 'A': None, # second
'z': [1, 2, 3, 4], 'Z': [1, 2, 3, 4, 5], 'O': [1, 4], 'v': [1, 4], # zone
'V': [1, 2, 3, 4], 'x': [1, 2, 3, 4, 5], 'X': [1, 2, 3, 4, 5] # zone
'V': [1, 2, 3, 4], 'x': [1, 2, 3, 4, 5], 'X': [1, 2, 3, 4, 5], # zone
}

#: The pattern characters declared in the Date Field Symbol Table
Expand Down
2 changes: 1 addition & 1 deletion babel/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def format_list(lst: Sequence[str],
if style not in locale.list_patterns:
raise ValueError(
f'Locale {locale} does not support list formatting style {style!r} '
f'(supported are {sorted(locale.list_patterns)})'
f'(supported are {sorted(locale.list_patterns)})',
)
patterns = locale.list_patterns[style]

Expand Down
2 changes: 1 addition & 1 deletion babel/localtime/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _get_tzinfo_or_raise(tzenv: str):
if tzinfo is None:
raise LookupError(
f"Can not find timezone {tzenv}. \n"
"Timezone names are generally in the form `Continent/City`."
"Timezone names are generally in the form `Continent/City`.",
)
return tzinfo

Expand Down
2 changes: 1 addition & 1 deletion babel/messages/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ def _merge(message: Message, oldkey: tuple[str, str] | str, newkey: tuple[str, s
if not isinstance(message.string, (list, tuple)):
fuzzy = True
message.string = tuple(
[message.string] + ([''] * (len(message.id) - 1))
[message.string] + ([''] * (len(message.id) - 1)),
)
elif len(message.string) != self.num_plurals:
fuzzy = True
Expand Down
4 changes: 2 additions & 2 deletions babel/messages/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
_string_format_compatibilities = [
{'i', 'd', 'u'},
{'x', 'X'},
{'f', 'F', 'g', 'G'}
{'f', 'F', 'g', 'G'},
]


Expand Down Expand Up @@ -150,7 +150,7 @@ def _check_positional(results: list[tuple[str, str]]) -> bool:
elif not _compatible(typechar, type_map[name]):
raise TranslationError(
f'incompatible format for placeholder {name!r}: '
f'{typechar!r} and {type_map[name]!r} are not compatible'
f'{typechar!r} and {type_map[name]!r} are not compatible',
)


Expand Down
10 changes: 5 additions & 5 deletions babel/messages/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def tell(self) -> int: ...
'dngettext': (2, 3),
'N_': None,
'pgettext': ((1, 'c'), 2),
'npgettext': ((1, 'c'), 2, 3)
'npgettext': ((1, 'c'), 2, 3),
}

DEFAULT_MAPPING: list[tuple[str, str]] = [('**.py', 'python')]
Expand Down Expand Up @@ -281,7 +281,7 @@ def check_and_call_extract_file(
keywords=keywords,
comment_tags=comment_tags,
options=options,
strip_comment_tags=strip_comment_tags
strip_comment_tags=strip_comment_tags,
):
yield (filename, *message_tuple)

Expand Down Expand Up @@ -352,7 +352,7 @@ def _match_messages_against_spec(lineno: int, messages: list[str|None], comments
filename = (getattr(fileobj, "name", None) or "(unknown)")
sys.stderr.write(
f"{filename}:{lineno}: warning: Empty msgid. It is reserved by GNU gettext: gettext(\"\") "
f"returns the header entry with meta information, not the empty string.\n"
f"returns the header entry with meta information, not the empty string.\n",
)
return

Expand Down Expand Up @@ -437,7 +437,7 @@ def extract(
builtin = {
'ignore': extract_nothing,
'python': extract_python,
'javascript': extract_javascript
'javascript': extract_javascript,
}
func = builtin.get(method)

Expand Down Expand Up @@ -690,7 +690,7 @@ def extract_javascript(
jsx=options.get("jsx", True),
template_string=options.get("template_string", True),
dotted=dotted,
lineno=lineno
lineno=lineno,
):
if ( # Turn keyword`foo` expressions into keyword("foo") calls:
funcname and # have a keyword...
Expand Down
30 changes: 15 additions & 15 deletions babel/messages/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class CompileCatalog(CommandMixin):
('use-fuzzy', 'f',
'also include fuzzy translations'),
('statistics', None,
'print statistics about translations')
'print statistics about translations'),
]
boolean_options = ['use-fuzzy', 'statistics']

Expand Down Expand Up @@ -246,7 +246,7 @@ def _run_domain(self, domain):
percentage = translated * 100 // len(catalog)
self.log.info(
'%d of %d messages (%d%%) translated in %s',
translated, len(catalog), percentage, po_file
translated, len(catalog), percentage, po_file,
)

if catalog.fuzzy and not self.use_fuzzy:
Expand All @@ -257,7 +257,7 @@ def _run_domain(self, domain):
for message, errors in catalog_errors:
for error in errors:
self.log.error(
'error: %s:%d: %s', po_file, message.lineno, error
'error: %s:%d: %s', po_file, message.lineno, error,
)

self.log.info('compiling catalog %s to %s', po_file, mo_file)
Expand Down Expand Up @@ -342,7 +342,7 @@ class ExtractMessages(CommandMixin):
]
boolean_options = [
'no-default-keywords', 'no-location', 'omit-header', 'no-wrap',
'sort-output', 'sort-by-file', 'strip-comments'
'sort-output', 'sort-by-file', 'strip-comments',
]
as_args = 'input-paths'
multiple_value_options = (
Expand All @@ -357,7 +357,7 @@ class ExtractMessages(CommandMixin):
'strip-comments': ('--strip-comment-tags',),
}
option_choices = {
'add-location': ('full', 'file', 'never',),
'add-location': ('full', 'file', 'never'),
}

def initialize_options(self):
Expand Down Expand Up @@ -391,7 +391,7 @@ def finalize_options(self):
self.input_paths = self.input_dirs
else:
raise OptionError(
'input-dirs and input-paths are mutually exclusive'
'input-dirs and input-paths are mutually exclusive',
)

keywords = {} if self.no_default_keywords else DEFAULT_KEYWORDS.copy()
Expand All @@ -402,14 +402,14 @@ def finalize_options(self):

if not self.keywords:
raise OptionError(
'you must specify new keywords if you disable the default ones'
'you must specify new keywords if you disable the default ones',
)

if not self.output_file:
raise OptionError('no output file specified')
if self.no_wrap and self.width:
raise OptionError(
"'--no-wrap' and '--width' are mutually exclusive"
"'--no-wrap' and '--width' are mutually exclusive",
)
if not self.no_wrap and not self.width:
self.width = 76
Expand All @@ -418,7 +418,7 @@ def finalize_options(self):

if self.sort_output and self.sort_by_file:
raise OptionError(
"'--sort-output' and '--sort-by-file' are mutually exclusive"
"'--sort-output' and '--sort-by-file' are mutually exclusive",
)

if self.input_paths:
Expand Down Expand Up @@ -497,7 +497,7 @@ def run(self):
extracted = check_and_call_extract_file(
path, method_map, options_map,
callback, self.keywords, self.add_comments,
self.strip_comments, current_dir
self.strip_comments, current_dir,
)
else:
extracted = extract_from_dir(
Expand Down Expand Up @@ -612,7 +612,7 @@ def finalize_options(self):

def run(self):
self.log.info(
'creating catalog %s based on %s', self.output_file, self.input_file
'creating catalog %s based on %s', self.output_file, self.input_file,
)

with open(self.input_file, 'rb') as infile:
Expand Down Expand Up @@ -701,7 +701,7 @@ def finalize_options(self):
if not self.locale:
raise OptionError(
'you must specify the locale for '
'the init-missing option to work'
'the init-missing option to work',
)

try:
Expand Down Expand Up @@ -755,7 +755,7 @@ def run(self):
check_status[filename] = False
continue
self.log.info(
'creating catalog %s based on %s', filename, self.input_file
'creating catalog %s based on %s', filename, self.input_file,
)

with open(self.input_file, 'rb') as infile:
Expand Down Expand Up @@ -841,7 +841,7 @@ class CommandLineInterface:
'compile': 'compile message catalogs to MO files',
'extract': 'extract messages from source files and generate a POT file',
'init': 'create new message catalogs from a POT file',
'update': 'update existing message catalogs from a POT file'
'update': 'update existing message catalogs from a POT file',
}

command_classes = {
Expand Down Expand Up @@ -935,7 +935,7 @@ def _configure_command(self, cmdname, argv):

parser = optparse.OptionParser(
usage=self.usage % (cmdname, ''),
description=self.commands[cmdname]
description=self.commands[cmdname],
)
as_args = getattr(cmdclass, "as_args", ())
for long, short, help in cmdclass.user_options:
Expand Down
4 changes: 2 additions & 2 deletions babel/messages/jslexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
'+', '-', '*', '%', '!=', '==', '<', '>', '<=', '>=', '=',
'+=', '-=', '*=', '%=', '<<', '>>', '>>>', '<<=', '>>=',
'>>>=', '&', '&=', '|', '|=', '&&', '||', '^', '^=', '(', ')',
'[', ']', '{', '}', '!', '--', '++', '~', ',', ';', '.', ':'
'[', ']', '{', '}', '!', '--', '++', '~', ',', ';', '.', ':',
], key=len, reverse=True)

escapes: dict[str, str] = {'b': '\b', 'f': '\f', 'n': '\n', 'r': '\r', 't': '\t'}
Expand Down Expand Up @@ -58,7 +58,7 @@ class Token(NamedTuple):
('string', re.compile(r'''(
'(?:[^'\\]*(?:\\.[^'\\]*)*)' |
"(?:[^"\\]*(?:\\.[^"\\]*)*)"
)''', re.VERBOSE | re.DOTALL))
)''', re.VERBOSE | re.DOTALL)),
]


Expand Down
2 changes: 1 addition & 1 deletion babel/messages/mofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,5 @@ def write_mo(fileobj: SupportsWrite[bytes], catalog: Catalog, use_fuzzy: bool =
len(messages), # number of entries
7 * 4, # start of key index
7 * 4 + len(messages) * 8, # start of value index
0, 0 # size and offset of hash table
0, 0, # size and offset of hash table
) + array.array.tobytes(array.array("i", offsets)) + ids + strs)
2 changes: 1 addition & 1 deletion babel/messages/plurals.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
6,
'(n==1 ? 0 : n%10==1 && n%100!=11 && n%100!=71 && n%100!=91 ? 1 : n%10==2 && n%100!=12 && n%100!=72 && '
'n%100!=92 ? 2 : (n%10==3 || n%10==4 || n%10==9) && n%100!=13 && n%100!=14 && n%100!=19 && n%100!=73 && '
'n%100!=74 && n%100!=79 && n%100!=93 && n%100!=94 && n%100!=99 ? 3 : n%1000000==0 ? 4 : 5)'
'n%100!=74 && n%100!=79 && n%100!=93 && n%100!=94 && n%100!=99 ? 3 : n%1000000==0 ? 4 : 5)',
),
# Bosnian
'bs': (3, '(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)'),
Expand Down
4 changes: 2 additions & 2 deletions babel/messages/pofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def _write_message(message, prefix=''):
)
if len(message.previous_id) > 1:
_write_comment('msgid_plural %s' % _normalize(
message.previous_id[1]
message.previous_id[1],
), prefix='|')

_write_message(message)
Expand All @@ -626,7 +626,7 @@ def _write_message(message, prefix=''):
if not ignore_obsolete:
for message in _sort_messages(
catalog.obsolete.values(),
sort_by=sort_by
sort_by=sort_by,
):
for comment in message.user_comments:
_write_comment(comment)
Expand Down
2 changes: 1 addition & 1 deletion babel/messages/setuptools_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def check_message_extractors(dist, name, value):
assert name == "message_extractors"
if not isinstance(value, dict):
raise SetupError(
'the value of the "message_extractors" parameter must be a dictionary'
'the value of the "message_extractors" parameter must be a dictionary',
)


Expand Down
4 changes: 2 additions & 2 deletions babel/numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ def format_compact_currency(
*,
format_type: Literal["short"] = "short",
locale: Locale | str | None = LC_NUMERIC,
fraction_digits: int = 0
fraction_digits: int = 0,
) -> str:
"""Format a number as a currency value in compact form.

Expand Down Expand Up @@ -1216,7 +1216,7 @@ def apply(
self._quantize_value(value, locale, frac_prec, group_separator),
get_exponential_symbol(locale),
exp_sign, # type: ignore # exp_sign is always defined here
self._format_int(str(exp), self.exp_prec[0], self.exp_prec[1], locale) # type: ignore # exp is always defined here
self._format_int(str(exp), self.exp_prec[0], self.exp_prec[1], locale), # type: ignore # exp is always defined here
])

# Is it a significant digits pattern?
Expand Down
2 changes: 1 addition & 1 deletion babel/plural.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class RuleError(Exception):
('word', re.compile(fr'\b(and|or|is|(?:with)?in|not|mod|[{"".join(_VARS)}])\b')),
('value', re.compile(r'\d+')),
('symbol', re.compile(r'%|,|!=|=')),
('ellipsis', re.compile(r'\.{2,3}|\u2026', re.UNICODE)) # U+2026: ELLIPSIS
('ellipsis', re.compile(r'\.{2,3}|\u2026', re.UNICODE)), # U+2026: ELLIPSIS
]


Expand Down
4 changes: 2 additions & 2 deletions babel/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def __copy__(self) -> LazyProxy:
self._func,
enable_cache=self._is_cache_enabled,
*self._args, # noqa: B026
**self._kwargs
**self._kwargs,
)

def __deepcopy__(self, memo: Any) -> LazyProxy:
Expand All @@ -353,7 +353,7 @@ def __deepcopy__(self, memo: Any) -> LazyProxy:
deepcopy(self._func, memo),
enable_cache=deepcopy(self._is_cache_enabled, memo),
*deepcopy(self._args, memo), # noqa: B026
**deepcopy(self._kwargs, memo)
**deepcopy(self._kwargs, memo),
)


Expand Down
2 changes: 1 addition & 1 deletion babel/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def format_compound_unit(
formatted_numerator = numerator_value
elif numerator_unit: # Numerator has unit
formatted_numerator = format_unit(
numerator_value, numerator_unit, length=length, format=format, locale=locale
numerator_value, numerator_unit, length=length, format=format, locale=locale,
)
else: # Unitless numerator
formatted_numerator = format_decimal(numerator_value, format=format, locale=locale)
Expand Down
Loading