summaryrefslogtreecommitdiff
path: root/babel/messages/extract.py
diff options
context:
space:
mode:
Diffstat (limited to 'babel/messages/extract.py')
-rw-r--r--babel/messages/extract.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/babel/messages/extract.py b/babel/messages/extract.py
index a426510..453742e 100644
--- a/babel/messages/extract.py
+++ b/babel/messages/extract.py
@@ -18,21 +18,29 @@
from __future__ import annotations
import ast
-from collections.abc import Callable, Collection, Generator, Iterable, Mapping, MutableSequence
import io
import os
import sys
+from collections.abc import (
+ Callable,
+ Collection,
+ Generator,
+ Iterable,
+ Mapping,
+ MutableSequence,
+)
from os.path import relpath
-from tokenize import generate_tokens, COMMENT, NAME, OP, STRING
-from typing import Any, TYPE_CHECKING
+from textwrap import dedent
+from tokenize import COMMENT, NAME, OP, STRING, generate_tokens
+from typing import TYPE_CHECKING, Any
from babel.util import parse_encoding, parse_future_flags, pathmatch
-from textwrap import dedent
if TYPE_CHECKING:
from typing import IO, Protocol
- from typing_extensions import Final, TypeAlias, TypedDict
+
from _typeshed import SupportsItems, SupportsRead, SupportsReadline
+ from typing_extensions import Final, TypeAlias, TypedDict
class _PyOptions(TypedDict, total=False):
encoding: str
@@ -82,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.
@@ -652,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:
@@ -786,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