From cd766b7848abbbee76fb37f5d1914b9b3d554f8f Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Mon, 13 Jan 2025 13:28:58 +0200 Subject: [PATCH] Fix minor pep8 complaints --- babel/messages/catalog.py | 3 ++- babel/messages/extract.py | 15 +++++++++------ tests/messages/test_pofile.py | 1 + tests/test_numbers.py | 2 ++ 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/babel/messages/catalog.py b/babel/messages/catalog.py index 3e7bb9e2..060b0eb7 100644 --- a/babel/messages/catalog.py +++ b/babel/messages/catalog.py @@ -37,6 +37,7 @@ __all__ = [ 'TranslationError', ] + def get_close_matches(word, possibilities, n=3, cutoff=0.6): """A modified version of ``difflib.get_close_matches``. @@ -48,7 +49,7 @@ def get_close_matches(word, possibilities, n=3, cutoff=0.6): if not 0.0 <= cutoff <= 1.0: # pragma: no cover raise ValueError(f"cutoff must be in [0.0, 1.0]: {cutoff!r}") result = [] - s = SequenceMatcher(autojunk=False) # only line changed from difflib.py + s = SequenceMatcher(autojunk=False) # only line changed from difflib.py s.set_seq2(word) for x in possibilities: s.set_seq1(x) diff --git a/babel/messages/extract.py b/babel/messages/extract.py index 94221df7..921e5c2c 100644 --- a/babel/messages/extract.py +++ b/babel/messages/extract.py @@ -325,15 +325,20 @@ def extract_from_file( options, strip_comment_tags)) -def _match_messages_against_spec(lineno: int, messages: list[str|None], comments: list[str], - fileobj: _FileObj, spec: tuple[int|tuple[int, str], ...]): +def _match_messages_against_spec( + lineno: int, + messages: list[str | None], + comments: list[str], + fileobj: _FileObj, + spec: tuple[int | tuple[int, str], ...], +): translatable = [] context = None # last_index is 1 based like the keyword spec last_index = len(messages) for index in spec: - if isinstance(index, tuple): # (n, 'c') + if isinstance(index, tuple): # (n, 'c') context = messages[index[0] - 1] continue if last_index < index: @@ -622,9 +627,7 @@ def extract_python( elif tok == NAME and value in keywords: funcname = value - if (current_fstring_start is not None - and tok not in {FSTRING_START, FSTRING_MIDDLE} - ): + if current_fstring_start is not None and tok not in {FSTRING_START, FSTRING_MIDDLE}: # In Python 3.12, tokens other than FSTRING_* mean the # f-string is dynamic, so we don't wan't to extract it. # And if it's FSTRING_END, we've already handled it above. diff --git a/tests/messages/test_pofile.py b/tests/messages/test_pofile.py index ab7c7f4b..9d430736 100644 --- a/tests/messages/test_pofile.py +++ b/tests/messages/test_pofile.py @@ -974,6 +974,7 @@ class RoundtripPoTestCase(unittest.TestCase): catalog2 = pofile.read_po(buf) assert True is catalog.is_identical(catalog2) + class PofileFunctionsTestCase(unittest.TestCase): def test_unescape(self): diff --git a/tests/test_numbers.py b/tests/test_numbers.py index f3e2dec7..e64fcfb7 100644 --- a/tests/test_numbers.py +++ b/tests/test_numbers.py @@ -420,6 +420,7 @@ def test_format_decimal(): with pytest.raises(numbers.UnsupportedNumberingSystemError): numbers.format_decimal(12345.5, locale='en_US', numbering_system="unknown") + @pytest.mark.parametrize('input_value, expected_value', [ ('10000', '10,000'), ('1', '1'), @@ -759,6 +760,7 @@ def test_parse_number(): with pytest.raises(numbers.UnsupportedNumberingSystemError): numbers.parse_number('1.099,98', locale='en', numbering_system="unsupported") + @pytest.mark.parametrize('string', [ '1 099', '1\xa0099', -- 2.47.2