Skip to content

Commit 82d345a

Browse files
committed
Apply some small miscellaneous formatting fixes
1 parent cb0269f commit 82d345a

20 files changed

Lines changed: 63 additions & 55 deletions

babel/core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
_global_data = None
4747
_default_plural_rule = PluralRule({})
4848

49+
4950
def _raise_no_data_error():
5051
raise RuntimeError('The babel data files are not available. '
5152
'This usually happens because you are using '

babel/dates.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,8 +1349,7 @@ def parse_date(
13491349
month_idx = format_str.index('l')
13501350
day_idx = format_str.index('d')
13511351

1352-
indexes = [(year_idx, 'Y'), (month_idx, 'M'), (day_idx, 'D')]
1353-
indexes.sort()
1352+
indexes = sorted([(year_idx, 'Y'), (month_idx, 'M'), (day_idx, 'D')])
13541353
indexes = {item[1]: idx for idx, item in enumerate(indexes)}
13551354

13561355
# FIXME: this currently only supports numbers, but should also support month
@@ -1399,8 +1398,7 @@ def parse_time(
13991398
min_idx = format_str.index('m')
14001399
sec_idx = format_str.index('s')
14011400

1402-
indexes = [(hour_idx, 'H'), (min_idx, 'M'), (sec_idx, 'S')]
1403-
indexes.sort()
1401+
indexes = sorted([(hour_idx, 'H'), (min_idx, 'M'), (sec_idx, 'S')])
14041402
indexes = {item[1]: idx for idx, item in enumerate(indexes)}
14051403

14061404
# TODO: support time zones
@@ -1436,7 +1434,7 @@ def __str__(self) -> str:
14361434
return pat
14371435

14381436
def __mod__(self, other: DateTimeFormat) -> str:
1439-
if type(other) is not DateTimeFormat:
1437+
if not isinstance(other, DateTimeFormat):
14401438
return NotImplemented
14411439
return self.format % other
14421440

@@ -1829,7 +1827,7 @@ def parse_pattern(pattern: str) -> DateTimePattern:
18291827
18301828
:param pattern: the formatting pattern to parse
18311829
"""
1832-
if type(pattern) is DateTimePattern:
1830+
if isinstance(pattern, DateTimePattern):
18331831
return pattern
18341832

18351833
if pattern in _pattern_cache:

babel/localtime/_helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def _get_tzinfo(tzenv: str):
2424

2525
return None
2626

27+
2728
def _get_tzinfo_or_raise(tzenv: str):
2829
tzinfo = _get_tzinfo(tzenv)
2930
if tzinfo is None:

babel/messages/catalog.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ class TranslationError(Exception):
240240
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
241241
#"""
242242

243+
243244
def parse_separated_header(value: str) -> dict[str, str]:
244245
# Adapted from https://peps.python.org/pep-0594/#cgi
245246
from email.message import Message
@@ -736,7 +737,8 @@ def delete(self, id: _MessageID, context: str | None = None) -> None:
736737
if key in self._messages:
737738
del self._messages[key]
738739

739-
def update(self,
740+
def update(
741+
self,
740742
template: Catalog,
741743
no_fuzzy_matching: bool = False,
742744
update_header_comment: bool = False,

babel/messages/extract.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ def tell(self) -> int: ...
9090
DEFAULT_MAPPING: list[tuple[str, str]] = [('**.py', 'python')]
9191

9292

93-
9493
def _strip_comment_tags(comments: MutableSequence[str], tags: Iterable[str]):
9594
"""Helper function for `extract` that strips comment tags from strings
9695
in a list of comment lines. This functions operates in-place.
@@ -660,8 +659,7 @@ def extract_javascript(
660659
token = Token('operator', ')', token.lineno)
661660

662661
if options.get('parse_template_string') and not funcname and token.type == 'template_string':
663-
for item in parse_template_string(token.value, keywords, comment_tags, options, token.lineno):
664-
yield item
662+
yield from parse_template_string(token.value, keywords, comment_tags, options, token.lineno)
665663

666664
elif token.type == 'operator' and token.value == '(':
667665
if funcname:
@@ -794,8 +792,7 @@ def parse_template_string(
794792
if level == 0 and expression_contents:
795793
expression_contents = expression_contents[0:-1]
796794
fake_file_obj = io.BytesIO(expression_contents.encode())
797-
for item in extract_javascript(fake_file_obj, keywords, comment_tags, options, lineno):
798-
yield item
795+
yield from extract_javascript(fake_file_obj, keywords, comment_tags, options, lineno)
799796
lineno += len(line_re.findall(expression_contents))
800797
expression_contents = ''
801798
prev_character = character

babel/messages/frontend.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
from distutils.errors import DistutilsSetupError as SetupError
5757

5858

59-
6059
def listify_value(arg, split=None):
6160
"""
6261
Make a list out of an argument.
@@ -853,7 +852,7 @@ def run(self):
853852
omit_header=self.omit_header,
854853
ignore_obsolete=self.ignore_obsolete,
855854
include_previous=self.previous, width=self.width)
856-
except:
855+
except Exception:
857856
os.remove(tmpname)
858857
raise
859858

babel/messages/jslexer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@
3232
uni_escape_re = re.compile(r'[a-fA-F0-9]{1,4}')
3333
hex_escape_re = re.compile(r'[a-fA-F0-9]{1,2}')
3434

35+
3536
class Token(NamedTuple):
3637
type: str
3738
value: str
3839
lineno: int
3940

41+
4042
_rules: list[tuple[str | None, re.Pattern[str]]] = [
4143
(None, re.compile(r'\s+', re.UNICODE)),
4244
(None, re.compile(r'<!--.*')),
@@ -100,7 +102,7 @@ def unquote_string(string: str) -> str:
100102
add = result.append
101103
pos = 0
102104

103-
while 1:
105+
while True:
104106
# scan for the next escape
105107
escape_pos = string.find('\\', pos)
106108
if escape_pos < 0:

babel/messages/pofile.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ def __ne__(self, other: object) -> bool:
134134
return self.__cmp__(other) != 0
135135

136136

137-
138137
class PoFileParser:
139138
"""Support class to read messages from a ``gettext`` PO (portable object) file
140139
and add them to a `Catalog`
@@ -615,11 +614,13 @@ def _write_message(message, prefix=''):
615614
locs.append(location)
616615
_write_comment(' '.join(locs), prefix=':')
617616
if message.flags:
618-
_write('#%s\n' % ', '.join([''] + sorted(message.flags)))
617+
_write(f"#{', '.join(['', *sorted(message.flags)])}\n")
619618

620619
if message.previous_id and include_previous:
621-
_write_comment('msgid %s' % _normalize(message.previous_id[0]),
622-
prefix='|')
620+
_write_comment(
621+
f'msgid {_normalize(message.previous_id[0])}',
622+
prefix='|',
623+
)
623624
if len(message.previous_id) > 1:
624625
_write_comment('msgid_plural %s' % _normalize(
625626
message.previous_id[1]

babel/plural.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ def cldr_modulo(a: float, b: float) -> float:
325325
class RuleError(Exception):
326326
"""Raised if a rule is malformed."""
327327

328+
328329
_VARS = {
329330
'n', # absolute value of the source number.
330331
'i', # integer digits of n.
@@ -363,6 +364,7 @@ def tokenize_rule(s: str) -> list[tuple[str, str]]:
363364
'Got unexpected %r' % s[pos])
364365
return result[::-1]
365366

367+
366368
def test_next_token(
367369
tokens: list[tuple[str, str]],
368370
type_: str,

babel/support.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
from babel.dates import _PredefinedTimeFormat
3737

38+
3839
class Format:
3940
"""Wrapper class providing the various date and number formatting functions
4041
bound to a specific locale and time-zone.

0 commit comments

Comments
 (0)