]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Minor cleanups (#948)
authorAarni Koskela <akx@iki.fi>
Wed, 18 Jan 2023 17:47:43 +0000 (19:47 +0200)
committerGitHub <noreply@github.com>
Wed, 18 Jan 2023 17:47:43 +0000 (19:47 +0200)
* Add __all__s to be cleaner about re-exports
* Move timezone_getter to conftest
* Apply spelling corrections suggested by codespell

16 files changed:
CHANGES.rst
babel/__init__.py
babel/core.py
babel/dates.py
babel/localedata.py
babel/messages/__init__.py
babel/messages/checkers.py
babel/messages/extract.py
babel/numbers.py
babel/plural.py
babel/support.py
tests/conftest.py
tests/test_date_intervals.py
tests/test_dates.py
tests/test_numbers.py
tests/test_support.py

index bee5c3f406938752f27b42d59e85dfbb5fcbc4fc..a146e8fbac690f13af88244d293639045312d174 100644 (file)
@@ -613,7 +613,7 @@ Version 1.0
 - Explicitly sort instead of using sorted() and don't assume ordering
   (Jython compatibility).
 - Removed ValueError raising for string formatting message checkers if the
-  string does not contain any string formattings (:trac:`150`).
+  string does not contain any string formatting (:trac:`150`).
 - Fix Serbian plural forms (:trac:`213`).
 - Small speed improvement in format_date() (:trac:`216`).
 - Fix so frontend.CommandLineInterface.run does not accumulate logging
@@ -690,7 +690,7 @@ Version 0.9.6
 - Explicitly sort instead of using sorted() and don't assume ordering
   (Python 2.3 and Jython compatibility).
 - Removed ValueError raising for string formatting message checkers if the
-  string does not contain any string formattings (:trac:`150`).
+  string does not contain any string formatting (:trac:`150`).
 - Fix Serbian plural forms (:trac:`213`).
 - Small speed improvement in format_date() (:trac:`216`).
 - Fix number formatting for locales where CLDR specifies alt or draft
index df190033cfafec71144e22f6ad6c1014b98f3066..be35c0361ee798576a7ff6e4f3f21e9453daaa12 100644 (file)
     :license: BSD, see LICENSE for more details.
 """
 
-from babel.core import UnknownLocaleError, Locale, default_locale, \
-    negotiate_locale, parse_locale, get_locale_identifier
-
+from babel.core import (
+    Locale,
+    UnknownLocaleError,
+    default_locale,
+    get_locale_identifier,
+    negotiate_locale,
+    parse_locale,
+)
 
 __version__ = '2.11.0'
+
+__all__ = [
+    'Locale',
+    'UnknownLocaleError',
+    'default_locale',
+    'get_locale_identifier',
+    'negotiate_locale',
+    'parse_locale',
+]
index 704957b7e181055585b982025f4c23838fa0adb7..5041c1bb920094f761bb5f99751dec05af34a6df 100644 (file)
@@ -239,13 +239,13 @@ class Locale:
         >>> Locale.negotiate(['de_DE', 'de'], ['en_US'])
 
         You can specify the character used in the locale identifiers to separate
-        the differnet components. This separator is applied to both lists. Also,
+        the different components. This separator is applied to both lists. Also,
         case is ignored in the comparison:
 
         >>> Locale.negotiate(['de-DE', 'de'], ['en-us', 'de-de'], sep='-')
         Locale('de', territory='DE')
 
-        :param preferred: the list of locale identifers preferred by the user
+        :param preferred: the list of locale identifiers preferred by the user
         :param available: the list of locale identifiers available
         :param aliases: a dictionary of aliases for locale identifiers
         """
index 05cfa251c638ec6eb4d22671469e387874c98545..51bc7ffcf97b56dbc2cc761aef72f3d95ce6cd8c 100644 (file)
@@ -1757,7 +1757,7 @@ class DateTimeFormat:
 
         :param day_of_period: the number of the day in the period (usually
                               either the day of month or the day of year)
-        :param day_of_week: the week day; if ommitted, the week day of the
+        :param day_of_week: the week day; if omitted, the week day of the
                             current date is assumed
         """
         if day_of_week is None:
index 0d3508d1e0589d4411759238446fb6a8429244a8..c14391aa7e7ff11df3eae82ded188532cc0932e2 100644 (file)
@@ -121,7 +121,7 @@ def load(name: os.PathLike[str] | str, merge_inherited: bool = True) -> dict[str
     :param merge_inherited: whether the inherited data should be merged into
                             the data of the requested locale
     :raise `IOError`: if no locale data file is found for the given locale
-                      identifer, or one of the locales it inherits from
+                      identifier, or one of the locales it inherits from
     """
     name = os.path.basename(name)
     _cache_lock.acquire()
index ad4fd346d52f595e2ae14ba971c2161fac9e3c38..60aeba0ed1af6c7c7fc6c57e7428f1fcf51c84c3 100644 (file)
@@ -8,4 +8,14 @@
     :license: BSD, see LICENSE for more details.
 """
 
-from babel.messages.catalog import *
+from babel.messages.catalog import (
+    Catalog,
+    Message,
+    TranslationError,
+)
+
+__all__ = [
+    "Catalog",
+    "Message",
+    "TranslationError",
+]
index 9231c678e6dd36e9cd3e2686e34b8ecabe68d20e..00b84e5e3082537d01ce945c99b5fb72ef301be8 100644 (file)
@@ -67,7 +67,7 @@ def _validate_format(format: str, alternative: str) -> None:
     placeholders if `format` uses named placeholders.
 
     The behavior of this function is undefined if the string does not use
-    string formattings.
+    string formatting.
 
     If the string formatting of `alternative` is compatible to `format` the
     function returns `None`, otherwise a `TranslationError` is raised.
index 5c331c0a5eb6657599e701439e49fea80319f88f..a4265101abed13e5ae7dad3c03e8ac95e775cc0e 100644 (file)
@@ -537,8 +537,8 @@ def extract_python(
                     messages = tuple(messages)
                 else:
                     messages = messages[0]
-                # Comments don't apply unless they immediately preceed the
-                # message
+                # Comments don't apply unless they immediately
+                # precede the message
                 if translator_comments and \
                         translator_comments[-1][0] < message_lineno - 1:
                     translator_comments = []
@@ -673,7 +673,7 @@ def extract_javascript(
                     break
 
         elif token.type == 'multilinecomment':
-            # only one multi-line comment may preceed a translation
+            # only one multi-line comment may precede a translation
             translator_comments = []
             value = token.value[2:-2].strip()
             for comment_tag in comment_tags:
index 95e9d2af0cd4b13a0164ed873059a24d2eec82d4..5a05f910e11e4465ee1309364106e8a90443c076 100644 (file)
@@ -93,7 +93,7 @@ def is_currency(currency: str, locale: Locale | str | None = None) -> bool:
 
 
 def normalize_currency(currency: str, locale: Locale | str | None = None) -> str | None:
-    """Returns the normalized sting of any currency code.
+    """Returns the normalized identifier of any currency code.
 
     Accepts a ``locale`` parameter for fined-grained validation, working as
     the one defined above in ``list_currencies()`` method.
@@ -1203,7 +1203,7 @@ class NumberPattern:
                 self._format_int(
                     str(exp), self.exp_prec[0], self.exp_prec[1], locale)])
 
-        # Is it a siginificant digits pattern?
+        # Is it a significant digits pattern?
         elif '@' in self.pattern:
             text = self._format_significant(value,
                                             self.int_prec[0],
index efd0f1f6a6f981732836e13238e998ffbbbb7183..b4f54c018287de34877e57c7f683972ac3b77fc4 100644 (file)
@@ -425,7 +425,7 @@ class _Parser:
       'n in 3,5,7..15'.
     - Samples are ignored.
 
-    The translator parses the expression on instanciation into an attribute
+    The translator parses the expression on instantiation into an attribute
     called `ast`.
     """
 
index da111fc264d0d6ca1ffa29c28bb040c16bb01a32..a8dd2305d5afacf45971df4dde3e1df2eaa015a9 100644 (file)
@@ -418,7 +418,7 @@ class NullTranslations(gettext.NullTranslations):
     # backward compatibility with 0.9
     dungettext = udngettext
 
-    # Most of the downwards code, until it get's included in stdlib, from:
+    # Most of the downwards code, until it gets included in stdlib, from:
     #    https://bugs.python.org/file10036/gettext-pgettext.patch
     #
     # The encoding of a msgctxt and a msgid in a .mo file is
index 5b14b1ca72350e2d83614befe3df8920ffd520e7..0506a833032e00b8b1a8adc1317e090c4f5de0c4 100644 (file)
@@ -1,6 +1,19 @@
 import os
 import pytest
 
+try:
+    import zoneinfo
+except ModuleNotFoundError:
+    try:
+        from backports import zoneinfo
+    except ImportError:
+        zoneinfo = None
+
+try:
+    import pytz
+except ModuleNotFoundError:
+    pytz = None
+
 
 @pytest.fixture
 def os_environ(monkeypatch):
@@ -16,3 +29,19 @@ def pytest_generate_tests(metafunc):
                 from babel.localedata import locale_identifiers
                 metafunc.parametrize("locale", list(locale_identifiers()))
                 break
+
+
+@pytest.fixture(params=["pytz.timezone", "zoneinfo.ZoneInfo"], scope="package")
+def timezone_getter(request):
+    if request.param == "pytz.timezone":
+        if pytz:
+            return pytz.timezone
+        else:
+            pytest.skip("pytz not available")
+    elif request.param == "zoneinfo.ZoneInfo":
+        if zoneinfo:
+            return zoneinfo.ZoneInfo
+        else:
+            pytest.skip("zoneinfo not available")
+    else:
+        raise NotImplementedError
index eb3aa89773c16d0d7a3012651a7bf4b8a3760b66..8e84a9eb60d2e73f34c4f0f59e42d6f50b935ccd 100644 (file)
@@ -2,7 +2,6 @@ import datetime
 
 from babel import dates
 from babel.util import UTC
-from .test_dates import timezone_getter
 
 TEST_DT = datetime.datetime(2016, 1, 8, 11, 46, 15)
 TEST_TIME = TEST_DT.time()
index 9fd73148bd2f2efa668fc2d3469578d8a2bead16..a4fb9c5bfd1c68709dbff59e03c3eceea3807d2b 100644 (file)
@@ -16,41 +16,11 @@ from datetime import date, datetime, time, timedelta
 import freezegun
 import pytest
 
-# for tests it can be useful to have both zoneinfo and pytz available
-try:
-    import zoneinfo
-except ModuleNotFoundError:
-    try:
-        from backports import zoneinfo
-    except ImportError:
-        zoneinfo = None
-
-try:
-    import pytz
-except ModuleNotFoundError:
-    pytz = None
-
 from babel import dates, Locale
-from babel.dates import NO_INHERITANCE_MARKER, _localize, _get_tz_name, LOCALTZ
+from babel.dates import NO_INHERITANCE_MARKER, _localize
 from babel.util import FixedOffsetTimezone
 
 
-@pytest.fixture(params=["pytz.timezone", "zoneinfo.ZoneInfo"], scope="package")
-def timezone_getter(request):
-    if request.param == "pytz.timezone":
-        if pytz:
-            return pytz.timezone
-        else:
-            pytest.skip("pytz not available")
-    elif request.param == "zoneinfo.ZoneInfo":
-        if zoneinfo:
-            return zoneinfo.ZoneInfo
-        else:
-            pytest.skip("zoneinfo not available")
-    else:
-        raise NotImplementedError
-
-
 class DateTimeFormatTestCase:
 
     def test_quarter_format(self):
index 37d2f9ec64808441fcde09a534662d988681943d..0939562bf548697f38b74869a7dabff1a45cff66 100644 (file)
@@ -28,7 +28,7 @@ class FormatDecimalTestCase(unittest.TestCase):
         assert numbers.format_decimal(12345, '##0', locale='en_US') == '12345'
         assert numbers.format_decimal(6.5, '0.00', locale='sv') == '6,50'
         assert numbers.format_decimal((10.0 ** 20), '#.00', locale='en_US') == '100000000000000000000.00'
-        # regression test for #183, fraction digits were not correctly cutted
+        # regression test for #183, fraction digits were not correctly cut
         # if the input was a float value and the value had more than 7
         # significant digits
         assert numbers.format_decimal(12345678.051, '#,##0.00', locale='en_US') == u'12,345,678.05'
index d39d8ef6d4b84782a7c29c07a4fa053e83f5634c..3ca0be3d63fa0a200f087543e1a24018bd9caf91 100644 (file)
@@ -23,8 +23,6 @@ from io import BytesIO
 from babel import support
 from babel.messages import Catalog
 from babel.messages.mofile import write_mo
-from babel.dates import get_timezone
-from .test_dates import timezone_getter
 
 
 SKIP_LGETTEXT = sys.version_info >= (3, 8)