Skip to content

Commit 8a1eef5

Browse files
authored
Enforce trailing commas (enable Ruff COM rule and autofix) (#1045)
1 parent bf7b2ca commit 8a1eef5

31 files changed

+128
-97
lines changed

babel/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def get_global(key: _GLOBAL_KEY) -> Mapping[str, Any]:
111111
'ja': 'ja_JP', 'km': 'km_KH', 'ko': 'ko_KR', 'lt': 'lt_LT', 'lv': 'lv_LV',
112112
'mk': 'mk_MK', 'nl': 'nl_NL', 'nn': 'nn_NO', 'no': 'nb_NO', 'pl': 'pl_PL',
113113
'pt': 'pt_PT', 'ro': 'ro_RO', 'ru': 'ru_RU', 'sk': 'sk_SK', 'sl': 'sl_SI',
114-
'sv': 'sv_SE', 'th': 'th_TH', 'tr': 'tr_TR', 'uk': 'uk_UA'
114+
'sv': 'sv_SE', 'th': 'th_TH', 'tr': 'tr_TR', 'uk': 'uk_UA',
115115
}
116116

117117

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

11501150
def parse_locale(
11511151
identifier: str,
1152-
sep: str = '_'
1152+
sep: str = '_',
11531153
) -> tuple[str, str | None, str | None, str | None] | tuple[str, str | None, str | None, str | None, str | None]:
11541154
"""Parse a locale identifier into a tuple of the form ``(language,
11551155
territory, script, variant, modifier)``.

babel/dates.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ def get_timezone_location(
521521
return city_name
522522
return region_format % (fallback_format % {
523523
'0': city_name,
524-
'1': territory_name
524+
'1': territory_name,
525525
})
526526

527527

@@ -852,7 +852,7 @@ def format_skeleton(
852852
('day', 3600 * 24),
853853
('hour', 3600),
854854
('minute', 60),
855-
('second', 1)
855+
('second', 1),
856856
)
857857

858858

@@ -1324,7 +1324,7 @@ def __init__(
13241324
self,
13251325
value: datetime.date | datetime.time,
13261326
locale: Locale | str,
1327-
reference_date: datetime.date | None = None
1327+
reference_date: datetime.date | None = None,
13281328
) -> None:
13291329
assert isinstance(value, (datetime.date, datetime.datetime, datetime.time))
13301330
if isinstance(value, (datetime.datetime, datetime.time)) and value.tzinfo is None:
@@ -1663,7 +1663,7 @@ def get_week_number(self, day_of_period: int, day_of_week: int | None = None) ->
16631663
'm': [1, 2], # minute
16641664
's': [1, 2], 'S': None, 'A': None, # second
16651665
'z': [1, 2, 3, 4], 'Z': [1, 2, 3, 4, 5], 'O': [1, 4], 'v': [1, 4], # zone
1666-
'V': [1, 2, 3, 4], 'x': [1, 2, 3, 4, 5], 'X': [1, 2, 3, 4, 5] # zone
1666+
'V': [1, 2, 3, 4], 'x': [1, 2, 3, 4, 5], 'X': [1, 2, 3, 4, 5], # zone
16671667
}
16681668

16691669
#: The pattern characters declared in the Date Field Symbol Table

babel/lists.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def format_list(lst: Sequence[str],
7979
if style not in locale.list_patterns:
8080
raise ValueError(
8181
f'Locale {locale} does not support list formatting style {style!r} '
82-
f'(supported are {sorted(locale.list_patterns)})'
82+
f'(supported are {sorted(locale.list_patterns)})',
8383
)
8484
patterns = locale.list_patterns[style]
8585

babel/localtime/_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _get_tzinfo_or_raise(tzenv: str):
3030
if tzinfo is None:
3131
raise LookupError(
3232
f"Can not find timezone {tzenv}. \n"
33-
"Timezone names are generally in the form `Continent/City`."
33+
"Timezone names are generally in the form `Continent/City`.",
3434
)
3535
return tzinfo
3636

babel/messages/catalog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ def _merge(message: Message, oldkey: tuple[str, str] | str, newkey: tuple[str, s
861861
if not isinstance(message.string, (list, tuple)):
862862
fuzzy = True
863863
message.string = tuple(
864-
[message.string] + ([''] * (len(message.id) - 1))
864+
[message.string] + ([''] * (len(message.id) - 1)),
865865
)
866866
elif len(message.string) != self.num_plurals:
867867
fuzzy = True

babel/messages/checkers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
_string_format_compatibilities = [
2020
{'i', 'd', 'u'},
2121
{'x', 'X'},
22-
{'f', 'F', 'g', 'G'}
22+
{'f', 'F', 'g', 'G'},
2323
]
2424

2525

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

156156

babel/messages/extract.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def tell(self) -> int: ...
8686
'dngettext': (2, 3),
8787
'N_': None,
8888
'pgettext': ((1, 'c'), 2),
89-
'npgettext': ((1, 'c'), 2, 3)
89+
'npgettext': ((1, 'c'), 2, 3),
9090
}
9191

9292
DEFAULT_MAPPING: list[tuple[str, str]] = [('**.py', 'python')]
@@ -281,7 +281,7 @@ def check_and_call_extract_file(
281281
keywords=keywords,
282282
comment_tags=comment_tags,
283283
options=options,
284-
strip_comment_tags=strip_comment_tags
284+
strip_comment_tags=strip_comment_tags,
285285
):
286286
yield (filename, *message_tuple)
287287

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

@@ -437,7 +437,7 @@ def extract(
437437
builtin = {
438438
'ignore': extract_nothing,
439439
'python': extract_python,
440-
'javascript': extract_javascript
440+
'javascript': extract_javascript,
441441
}
442442
func = builtin.get(method)
443443

@@ -690,7 +690,7 @@ def extract_javascript(
690690
jsx=options.get("jsx", True),
691691
template_string=options.get("template_string", True),
692692
dotted=dotted,
693-
lineno=lineno
693+
lineno=lineno,
694694
):
695695
if ( # Turn keyword`foo` expressions into keyword("foo") calls:
696696
funcname and # have a keyword...

babel/messages/frontend.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class CompileCatalog(CommandMixin):
166166
('use-fuzzy', 'f',
167167
'also include fuzzy translations'),
168168
('statistics', None,
169-
'print statistics about translations')
169+
'print statistics about translations'),
170170
]
171171
boolean_options = ['use-fuzzy', 'statistics']
172172

@@ -246,7 +246,7 @@ def _run_domain(self, domain):
246246
percentage = translated * 100 // len(catalog)
247247
self.log.info(
248248
'%d of %d messages (%d%%) translated in %s',
249-
translated, len(catalog), percentage, po_file
249+
translated, len(catalog), percentage, po_file,
250250
)
251251

252252
if catalog.fuzzy and not self.use_fuzzy:
@@ -257,7 +257,7 @@ def _run_domain(self, domain):
257257
for message, errors in catalog_errors:
258258
for error in errors:
259259
self.log.error(
260-
'error: %s:%d: %s', po_file, message.lineno, error
260+
'error: %s:%d: %s', po_file, message.lineno, error,
261261
)
262262

263263
self.log.info('compiling catalog %s to %s', po_file, mo_file)
@@ -342,7 +342,7 @@ class ExtractMessages(CommandMixin):
342342
]
343343
boolean_options = [
344344
'no-default-keywords', 'no-location', 'omit-header', 'no-wrap',
345-
'sort-output', 'sort-by-file', 'strip-comments'
345+
'sort-output', 'sort-by-file', 'strip-comments',
346346
]
347347
as_args = 'input-paths'
348348
multiple_value_options = (
@@ -357,7 +357,7 @@ class ExtractMessages(CommandMixin):
357357
'strip-comments': ('--strip-comment-tags',),
358358
}
359359
option_choices = {
360-
'add-location': ('full', 'file', 'never',),
360+
'add-location': ('full', 'file', 'never'),
361361
}
362362

363363
def initialize_options(self):
@@ -391,7 +391,7 @@ def finalize_options(self):
391391
self.input_paths = self.input_dirs
392392
else:
393393
raise OptionError(
394-
'input-dirs and input-paths are mutually exclusive'
394+
'input-dirs and input-paths are mutually exclusive',
395395
)
396396

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

403403
if not self.keywords:
404404
raise OptionError(
405-
'you must specify new keywords if you disable the default ones'
405+
'you must specify new keywords if you disable the default ones',
406406
)
407407

408408
if not self.output_file:
409409
raise OptionError('no output file specified')
410410
if self.no_wrap and self.width:
411411
raise OptionError(
412-
"'--no-wrap' and '--width' are mutually exclusive"
412+
"'--no-wrap' and '--width' are mutually exclusive",
413413
)
414414
if not self.no_wrap and not self.width:
415415
self.width = 76
@@ -418,7 +418,7 @@ def finalize_options(self):
418418

419419
if self.sort_output and self.sort_by_file:
420420
raise OptionError(
421-
"'--sort-output' and '--sort-by-file' are mutually exclusive"
421+
"'--sort-output' and '--sort-by-file' are mutually exclusive",
422422
)
423423

424424
if self.input_paths:
@@ -497,7 +497,7 @@ def run(self):
497497
extracted = check_and_call_extract_file(
498498
path, method_map, options_map,
499499
callback, self.keywords, self.add_comments,
500-
self.strip_comments, current_dir
500+
self.strip_comments, current_dir,
501501
)
502502
else:
503503
extracted = extract_from_dir(
@@ -612,7 +612,7 @@ def finalize_options(self):
612612

613613
def run(self):
614614
self.log.info(
615-
'creating catalog %s based on %s', self.output_file, self.input_file
615+
'creating catalog %s based on %s', self.output_file, self.input_file,
616616
)
617617

618618
with open(self.input_file, 'rb') as infile:
@@ -701,7 +701,7 @@ def finalize_options(self):
701701
if not self.locale:
702702
raise OptionError(
703703
'you must specify the locale for '
704-
'the init-missing option to work'
704+
'the init-missing option to work',
705705
)
706706

707707
try:
@@ -755,7 +755,7 @@ def run(self):
755755
check_status[filename] = False
756756
continue
757757
self.log.info(
758-
'creating catalog %s based on %s', filename, self.input_file
758+
'creating catalog %s based on %s', filename, self.input_file,
759759
)
760760

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

847847
command_classes = {
@@ -935,7 +935,7 @@ def _configure_command(self, cmdname, argv):
935935

936936
parser = optparse.OptionParser(
937937
usage=self.usage % (cmdname, ''),
938-
description=self.commands[cmdname]
938+
description=self.commands[cmdname],
939939
)
940940
as_args = getattr(cmdclass, "as_args", ())
941941
for long, short, help in cmdclass.user_options:

babel/messages/jslexer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
'+', '-', '*', '%', '!=', '==', '<', '>', '<=', '>=', '=',
1919
'+=', '-=', '*=', '%=', '<<', '>>', '>>>', '<<=', '>>=',
2020
'>>>=', '&', '&=', '|', '|=', '&&', '||', '^', '^=', '(', ')',
21-
'[', ']', '{', '}', '!', '--', '++', '~', ',', ';', '.', ':'
21+
'[', ']', '{', '}', '!', '--', '++', '~', ',', ';', '.', ':',
2222
], key=len, reverse=True)
2323

2424
escapes: dict[str, str] = {'b': '\b', 'f': '\f', 'n': '\n', 'r': '\r', 't': '\t'}
@@ -58,7 +58,7 @@ class Token(NamedTuple):
5858
('string', re.compile(r'''(
5959
'(?:[^'\\]*(?:\\.[^'\\]*)*)' |
6060
"(?:[^"\\]*(?:\\.[^"\\]*)*)"
61-
)''', re.VERBOSE | re.DOTALL))
61+
)''', re.VERBOSE | re.DOTALL)),
6262
]
6363

6464

babel/messages/mofile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,5 +208,5 @@ def write_mo(fileobj: SupportsWrite[bytes], catalog: Catalog, use_fuzzy: bool =
208208
len(messages), # number of entries
209209
7 * 4, # start of key index
210210
7 * 4 + len(messages) * 8, # start of value index
211-
0, 0 # size and offset of hash table
211+
0, 0, # size and offset of hash table
212212
) + array.array.tobytes(array.array("i", offsets)) + ids + strs)

babel/messages/plurals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
6,
6666
'(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 && '
6767
'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 && '
68-
'n%100!=74 && n%100!=79 && n%100!=93 && n%100!=94 && n%100!=99 ? 3 : n%1000000==0 ? 4 : 5)'
68+
'n%100!=74 && n%100!=79 && n%100!=93 && n%100!=94 && n%100!=99 ? 3 : n%1000000==0 ? 4 : 5)',
6969
),
7070
# Bosnian
7171
'bs': (3, '(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)'),

babel/messages/pofile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ def _write_message(message, prefix=''):
617617
)
618618
if len(message.previous_id) > 1:
619619
_write_comment('msgid_plural %s' % _normalize(
620-
message.previous_id[1]
620+
message.previous_id[1],
621621
), prefix='|')
622622

623623
_write_message(message)
@@ -626,7 +626,7 @@ def _write_message(message, prefix=''):
626626
if not ignore_obsolete:
627627
for message in _sort_messages(
628628
catalog.obsolete.values(),
629-
sort_by=sort_by
629+
sort_by=sort_by,
630630
):
631631
for comment in message.user_comments:
632632
_write_comment(comment)

babel/messages/setuptools_frontend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def check_message_extractors(dist, name, value):
2828
assert name == "message_extractors"
2929
if not isinstance(value, dict):
3030
raise SetupError(
31-
'the value of the "message_extractors" parameter must be a dictionary'
31+
'the value of the "message_extractors" parameter must be a dictionary',
3232
)
3333

3434

babel/numbers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ def format_compact_currency(
721721
*,
722722
format_type: Literal["short"] = "short",
723723
locale: Locale | str | None = LC_NUMERIC,
724-
fraction_digits: int = 0
724+
fraction_digits: int = 0,
725725
) -> str:
726726
"""Format a number as a currency value in compact form.
727727
@@ -1216,7 +1216,7 @@ def apply(
12161216
self._quantize_value(value, locale, frac_prec, group_separator),
12171217
get_exponential_symbol(locale),
12181218
exp_sign, # type: ignore # exp_sign is always defined here
1219-
self._format_int(str(exp), self.exp_prec[0], self.exp_prec[1], locale) # type: ignore # exp is always defined here
1219+
self._format_int(str(exp), self.exp_prec[0], self.exp_prec[1], locale), # type: ignore # exp is always defined here
12201220
])
12211221

12221222
# Is it a significant digits pattern?

babel/plural.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ class RuleError(Exception):
342342
('word', re.compile(fr'\b(and|or|is|(?:with)?in|not|mod|[{"".join(_VARS)}])\b')),
343343
('value', re.compile(r'\d+')),
344344
('symbol', re.compile(r'%|,|!=|=')),
345-
('ellipsis', re.compile(r'\.{2,3}|\u2026', re.UNICODE)) # U+2026: ELLIPSIS
345+
('ellipsis', re.compile(r'\.{2,3}|\u2026', re.UNICODE)), # U+2026: ELLIPSIS
346346
]
347347

348348

babel/support.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def __copy__(self) -> LazyProxy:
344344
self._func,
345345
enable_cache=self._is_cache_enabled,
346346
*self._args, # noqa: B026
347-
**self._kwargs
347+
**self._kwargs,
348348
)
349349

350350
def __deepcopy__(self, memo: Any) -> LazyProxy:
@@ -353,7 +353,7 @@ def __deepcopy__(self, memo: Any) -> LazyProxy:
353353
deepcopy(self._func, memo),
354354
enable_cache=deepcopy(self._is_cache_enabled, memo),
355355
*deepcopy(self._args, memo), # noqa: B026
356-
**deepcopy(self._kwargs, memo)
356+
**deepcopy(self._kwargs, memo),
357357
)
358358

359359

babel/units.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def format_compound_unit(
271271
formatted_numerator = numerator_value
272272
elif numerator_unit: # Numerator has unit
273273
formatted_numerator = format_unit(
274-
numerator_value, numerator_unit, length=length, format=format, locale=locale
274+
numerator_value, numerator_unit, length=length, format=format, locale=locale,
275275
)
276276
else: # Unitless numerator
277277
formatted_numerator = format_decimal(numerator_value, format=format, locale=locale)

0 commit comments

Comments
 (0)