From 2d8a808864d1aae5d3d02d4f95917c79740c5d35 Mon Sep 17 00:00:00 2001 From: "Tomas R." Date: Sat, 25 Jan 2025 09:48:00 +0100 Subject: [PATCH] Import `Literal` & `TypedDict` from the typing module (#1175) * Import 'Literal' from the typing module * Import 'TypedDict' from the typing module --- babel/core.py | 4 ++-- babel/dates.py | 4 ++-- babel/lists.py | 7 +------ babel/messages/extract.py | 4 ++-- babel/messages/pofile.py | 3 +-- babel/numbers.py | 5 +---- babel/plural.py | 5 +---- babel/support.py | 4 +--- babel/units.py | 5 +---- 9 files changed, 12 insertions(+), 29 deletions(-) diff --git a/babel/core.py b/babel/core.py index 39a2cf6ed..1c7732b53 100644 --- a/babel/core.py +++ b/babel/core.py @@ -13,7 +13,7 @@ import os import pickle from collections.abc import Iterable, Mapping -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING, Any, Literal from babel import localedata from babel.plural import PluralRule @@ -29,7 +29,7 @@ ] if TYPE_CHECKING: - from typing_extensions import Literal, TypeAlias + from typing_extensions import TypeAlias _GLOBAL_KEY: TypeAlias = Literal[ "all_currencies", diff --git a/babel/dates.py b/babel/dates.py index 98dd3f044..8a4932d4b 100644 --- a/babel/dates.py +++ b/babel/dates.py @@ -21,7 +21,7 @@ import re import warnings from functools import lru_cache -from typing import TYPE_CHECKING, SupportsInt +from typing import TYPE_CHECKING, Literal, SupportsInt try: import pytz @@ -37,7 +37,7 @@ from babel.localedata import LocaleDataDict if TYPE_CHECKING: - from typing_extensions import Literal, TypeAlias + from typing_extensions import TypeAlias _Instant: TypeAlias = datetime.date | datetime.time | float | None _PredefinedTimeFormat: TypeAlias = Literal['full', 'long', 'medium', 'short'] _Context: TypeAlias = Literal['format', 'stand-alone'] diff --git a/babel/lists.py b/babel/lists.py index f1d3790d1..103a17713 100644 --- a/babel/lists.py +++ b/babel/lists.py @@ -17,15 +17,10 @@ import warnings from collections.abc import Sequence -from typing import TYPE_CHECKING +from typing import Literal from babel.core import Locale, default_locale -if TYPE_CHECKING: - from typing_extensions import Literal - - - _DEFAULT_LOCALE = default_locale() # TODO(3.0): Remove this. diff --git a/babel/messages/extract.py b/babel/messages/extract.py index 1c86e4ac8..6dd031382 100644 --- a/babel/messages/extract.py +++ b/babel/messages/extract.py @@ -34,7 +34,7 @@ from os.path import relpath from textwrap import dedent from tokenize import COMMENT, NAME, NL, OP, STRING, generate_tokens -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING, Any, TypedDict from babel.messages._compat import find_entrypoints from babel.util import parse_encoding, parse_future_flags, pathmatch @@ -43,7 +43,7 @@ from typing import IO, Final, Protocol from _typeshed import SupportsItems, SupportsRead, SupportsReadline - from typing_extensions import TypeAlias, TypedDict + from typing_extensions import TypeAlias class _PyOptions(TypedDict, total=False): encoding: str diff --git a/babel/messages/pofile.py b/babel/messages/pofile.py index a292c8a0c..ad9b07ad0 100644 --- a/babel/messages/pofile.py +++ b/babel/messages/pofile.py @@ -13,7 +13,7 @@ import os import re from collections.abc import Iterable -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Literal from babel.core import Locale from babel.messages.catalog import Catalog, Message @@ -23,7 +23,6 @@ from typing import IO, AnyStr from _typeshed import SupportsWrite - from typing_extensions import Literal def unescape(string: str) -> str: diff --git a/babel/numbers.py b/babel/numbers.py index 6d334918a..a2b89cc31 100644 --- a/babel/numbers.py +++ b/babel/numbers.py @@ -23,14 +23,11 @@ import decimal import re import warnings -from typing import TYPE_CHECKING, Any, cast, overload +from typing import Any, Literal, cast, overload from babel.core import Locale, default_locale, get_global from babel.localedata import LocaleDataDict -if TYPE_CHECKING: - from typing_extensions import Literal - LC_NUMERIC = default_locale('LC_NUMERIC') diff --git a/babel/plural.py b/babel/plural.py index 528d4175e..a2e30f456 100644 --- a/babel/plural.py +++ b/babel/plural.py @@ -12,10 +12,7 @@ import decimal import re from collections.abc import Iterable, Mapping -from typing import TYPE_CHECKING, Any, Callable - -if TYPE_CHECKING: - from typing_extensions import Literal +from typing import Any, Callable, Literal _plural_tags = ('zero', 'one', 'two', 'few', 'many', 'other') _fallback_tag = 'other' diff --git a/babel/support.py b/babel/support.py index ad9582809..4374a0ce0 100644 --- a/babel/support.py +++ b/babel/support.py @@ -16,7 +16,7 @@ import locale import os from collections.abc import Iterator -from typing import TYPE_CHECKING, Any, Callable, Iterable +from typing import TYPE_CHECKING, Any, Callable, Iterable, Literal from babel.core import Locale from babel.dates import format_date, format_datetime, format_time, format_timedelta @@ -33,8 +33,6 @@ import datetime as _datetime from decimal import Decimal - from typing_extensions import Literal - from babel.dates import _PredefinedTimeFormat diff --git a/babel/units.py b/babel/units.py index d7d5e84f5..86ac2abc9 100644 --- a/babel/units.py +++ b/babel/units.py @@ -1,14 +1,11 @@ from __future__ import annotations import decimal -from typing import TYPE_CHECKING +from typing import Literal from babel.core import Locale from babel.numbers import LC_NUMERIC, format_decimal -if TYPE_CHECKING: - from typing_extensions import Literal - class UnknownUnitError(ValueError): def __init__(self, unit: str, locale: Locale) -> None: