Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import Literal from the typing module #1175

Merged
merged 2 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions babel/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,7 +29,7 @@
]

if TYPE_CHECKING:
from typing_extensions import Literal, TypeAlias
from typing_extensions import TypeAlias

_GLOBAL_KEY: TypeAlias = Literal[
"all_currencies",
Expand Down
4 changes: 2 additions & 2 deletions babel/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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']
Expand Down
7 changes: 1 addition & 6 deletions babel/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down
4 changes: 2 additions & 2 deletions babel/messages/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions babel/messages/pofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,7 +23,6 @@
from typing import IO, AnyStr

from _typeshed import SupportsWrite
from typing_extensions import Literal


def unescape(string: str) -> str:
Expand Down
5 changes: 1 addition & 4 deletions babel/numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')


Expand Down
5 changes: 1 addition & 4 deletions babel/plural.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 1 addition & 3 deletions babel/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,8 +33,6 @@
import datetime as _datetime
from decimal import Decimal

from typing_extensions import Literal

from babel.dates import _PredefinedTimeFormat


Expand Down
5 changes: 1 addition & 4 deletions babel/units.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Loading