From: Aarni Koskela Date: Wed, 18 Jan 2023 18:27:44 +0000 (+0200) Subject: Apply some small miscellaneous formatting fixes X-Git-Tag: v2.12.0~19^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=82d345a66e850f643607ac9fcafd9b9a2a89d1e1;p=thirdparty%2Fbabel.git Apply some small miscellaneous formatting fixes --- diff --git a/babel/core.py b/babel/core.py index 604e5d9e..ce564d75 100644 --- a/babel/core.py +++ b/babel/core.py @@ -46,6 +46,7 @@ if TYPE_CHECKING: _global_data = None _default_plural_rule = PluralRule({}) + def _raise_no_data_error(): raise RuntimeError('The babel data files are not available. ' 'This usually happens because you are using ' diff --git a/babel/dates.py b/babel/dates.py index 26766a69..e626df5c 100644 --- a/babel/dates.py +++ b/babel/dates.py @@ -1349,8 +1349,7 @@ def parse_date( month_idx = format_str.index('l') day_idx = format_str.index('d') - indexes = [(year_idx, 'Y'), (month_idx, 'M'), (day_idx, 'D')] - indexes.sort() + indexes = sorted([(year_idx, 'Y'), (month_idx, 'M'), (day_idx, 'D')]) indexes = {item[1]: idx for idx, item in enumerate(indexes)} # FIXME: this currently only supports numbers, but should also support month @@ -1399,8 +1398,7 @@ def parse_time( min_idx = format_str.index('m') sec_idx = format_str.index('s') - indexes = [(hour_idx, 'H'), (min_idx, 'M'), (sec_idx, 'S')] - indexes.sort() + indexes = sorted([(hour_idx, 'H'), (min_idx, 'M'), (sec_idx, 'S')]) indexes = {item[1]: idx for idx, item in enumerate(indexes)} # TODO: support time zones @@ -1436,7 +1434,7 @@ class DateTimePattern: return pat def __mod__(self, other: DateTimeFormat) -> str: - if type(other) is not DateTimeFormat: + if not isinstance(other, DateTimeFormat): return NotImplemented return self.format % other @@ -1829,7 +1827,7 @@ def parse_pattern(pattern: str) -> DateTimePattern: :param pattern: the formatting pattern to parse """ - if type(pattern) is DateTimePattern: + if isinstance(pattern, DateTimePattern): return pattern if pattern in _pattern_cache: diff --git a/babel/localtime/_helpers.py b/babel/localtime/_helpers.py index b7238f6a..159f9a56 100644 --- a/babel/localtime/_helpers.py +++ b/babel/localtime/_helpers.py @@ -24,6 +24,7 @@ def _get_tzinfo(tzenv: str): return None + def _get_tzinfo_or_raise(tzenv: str): tzinfo = _get_tzinfo(tzenv) if tzinfo is None: diff --git a/babel/messages/catalog.py b/babel/messages/catalog.py index 85f16b25..dead4aac 100644 --- a/babel/messages/catalog.py +++ b/babel/messages/catalog.py @@ -240,6 +240,7 @@ DEFAULT_HEADER = """\ # FIRST AUTHOR , YEAR. #""" + def parse_separated_header(value: str) -> dict[str, str]: # Adapted from https://peps.python.org/pep-0594/#cgi from email.message import Message @@ -736,7 +737,8 @@ class Catalog: if key in self._messages: del self._messages[key] - def update(self, + def update( + self, template: Catalog, no_fuzzy_matching: bool = False, update_header_comment: bool = False, diff --git a/babel/messages/extract.py b/babel/messages/extract.py index 0934937c..453742ed 100644 --- a/babel/messages/extract.py +++ b/babel/messages/extract.py @@ -90,7 +90,6 @@ DEFAULT_KEYWORDS: dict[str, _Keyword] = { DEFAULT_MAPPING: list[tuple[str, str]] = [('**.py', 'python')] - def _strip_comment_tags(comments: MutableSequence[str], tags: Iterable[str]): """Helper function for `extract` that strips comment tags from strings in a list of comment lines. This functions operates in-place. @@ -660,8 +659,7 @@ def extract_javascript( token = Token('operator', ')', token.lineno) if options.get('parse_template_string') and not funcname and token.type == 'template_string': - for item in parse_template_string(token.value, keywords, comment_tags, options, token.lineno): - yield item + yield from parse_template_string(token.value, keywords, comment_tags, options, token.lineno) elif token.type == 'operator' and token.value == '(': if funcname: @@ -794,8 +792,7 @@ def parse_template_string( if level == 0 and expression_contents: expression_contents = expression_contents[0:-1] fake_file_obj = io.BytesIO(expression_contents.encode()) - for item in extract_javascript(fake_file_obj, keywords, comment_tags, options, lineno): - yield item + yield from extract_javascript(fake_file_obj, keywords, comment_tags, options, lineno) lineno += len(line_re.findall(expression_contents)) expression_contents = '' prev_character = character diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py index de17b1ea..ab094ecd 100644 --- a/babel/messages/frontend.py +++ b/babel/messages/frontend.py @@ -56,7 +56,6 @@ except ImportError: from distutils.errors import DistutilsSetupError as SetupError - def listify_value(arg, split=None): """ Make a list out of an argument. @@ -853,7 +852,7 @@ class update_catalog(Command): omit_header=self.omit_header, ignore_obsolete=self.ignore_obsolete, include_previous=self.previous, width=self.width) - except: + except Exception: os.remove(tmpname) raise diff --git a/babel/messages/jslexer.py b/babel/messages/jslexer.py index d2ffbbe7..0563f622 100644 --- a/babel/messages/jslexer.py +++ b/babel/messages/jslexer.py @@ -32,11 +32,13 @@ line_join_re = re.compile(r'\\' + line_re.pattern) uni_escape_re = re.compile(r'[a-fA-F0-9]{1,4}') hex_escape_re = re.compile(r'[a-fA-F0-9]{1,2}') + class Token(NamedTuple): type: str value: str lineno: int + _rules: list[tuple[str | None, re.Pattern[str]]] = [ (None, re.compile(r'\s+', re.UNICODE)), (None, re.compile(r'