Skip to content

Commit a8d195e

Browse files
committed
Make typing_extensions only required for type checking
1 parent b663dc1 commit a8d195e

7 files changed

Lines changed: 38 additions & 32 deletions

File tree

babel/core.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,37 @@
1313
import os
1414
import pickle
1515
from collections.abc import Iterable, Mapping
16-
from typing import Any, overload
17-
18-
from typing_extensions import Literal, TypeAlias
16+
from typing import TYPE_CHECKING, Any, overload
1917

2018
from babel import localedata
2119
from babel.plural import PluralRule
2220

2321
__all__ = ['UnknownLocaleError', 'Locale', 'default_locale', 'negotiate_locale',
2422
'parse_locale']
2523

26-
_GLOBAL_KEY: TypeAlias = Literal[
27-
"all_currencies",
28-
"currency_fractions",
29-
"language_aliases",
30-
"likely_subtags",
31-
"parent_exceptions",
32-
"script_aliases",
33-
"territory_aliases",
34-
"territory_currencies",
35-
"territory_languages",
36-
"territory_zones",
37-
"variant_aliases",
38-
"windows_zone_mapping",
39-
"zone_aliases",
40-
"zone_territories",
41-
]
42-
43-
_global_data: Mapping[_GLOBAL_KEY, Mapping[str, Any]] | None = None
24+
if TYPE_CHECKING:
25+
from typing_extensions import Literal, TypeAlias
26+
27+
_GLOBAL_KEY: TypeAlias = Literal[
28+
"all_currencies",
29+
"currency_fractions",
30+
"language_aliases",
31+
"likely_subtags",
32+
"parent_exceptions",
33+
"script_aliases",
34+
"territory_aliases",
35+
"territory_currencies",
36+
"territory_languages",
37+
"territory_zones",
38+
"variant_aliases",
39+
"windows_zone_mapping",
40+
"zone_aliases",
41+
"zone_territories",
42+
]
43+
44+
_global_data: Mapping[_GLOBAL_KEY, Mapping[str, Any]] | None
45+
46+
_global_data = None
4447
_default_plural_rule = PluralRule({})
4548

4649
def _raise_no_data_error():

babel/dates.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@
2525
from typing import TYPE_CHECKING, SupportsInt
2626

2727
import pytz as _pytz
28-
from typing_extensions import Literal, TypeAlias
2928

3029
from babel.core import Locale, default_locale, get_global
3130
from babel.localedata import LocaleDataDict
3231
from babel.util import LOCALTZ, UTC
3332

3433
if TYPE_CHECKING:
34+
from typing_extensions import Literal, TypeAlias
35+
3536
_Instant: TypeAlias = date | time | float | None
3637
_PredefinedTimeFormat: TypeAlias = Literal["full", "long", "medium", "short"]
3738
_Context: TypeAlias = Literal["format", "stand-alone"]
@@ -1123,7 +1124,7 @@ def format_interval(start: _Instant, end: _Instant, skeleton: str | None = None,
11231124
return _format_fallback_interval(start, end, skeleton, tzinfo, locale)
11241125

11251126

1126-
def get_period_id(time: _Instant, tzinfo: BaseTzInfo | None = None, type: Literal["selection"] | None = None,
1127+
def get_period_id(time: _Instant, tzinfo: _pytz.BaseTzInfo | None = None, type: Literal["selection"] | None = None,
11271128
locale: Locale | str | None = LC_TIME) -> str:
11281129
"""
11291130
Get the day period ID for a given time.

babel/lists.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
from __future__ import annotations
1717

1818
from collections.abc import Sequence
19-
20-
from typing_extensions import Literal
19+
from typing import TYPE_CHECKING
2120

2221
from babel.core import Locale, default_locale
2322

23+
if TYPE_CHECKING:
24+
from typing_extensions import Literal
25+
2426
DEFAULT_LOCALE = default_locale()
2527

2628

babel/numbers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@
2121

2222
import decimal
2323
import re
24+
from typing import TYPE_CHECKING
2425
import warnings
2526
from datetime import date as date_, datetime as datetime_
2627

27-
from typing_extensions import Literal
28-
2928
from babel.core import Locale, default_locale, get_global
3029
from babel.localedata import LocaleDataDict
3130

31+
if TYPE_CHECKING:
32+
from typing_extensions import Literal
33+
3234
LC_NUMERIC = default_locale('LC_NUMERIC')
3335

3436

babel/units.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from __future__ import annotations
22

33
import decimal
4-
5-
from typing_extensions import Literal
4+
from typing import TYPE_CHECKING
65

76
from babel.core import Locale
8-
from babel.localedata import LocaleDataDict
97
from babel.numbers import LC_NUMERIC, format_decimal
108

9+
if TYPE_CHECKING:
10+
from typing_extensions import Literal
1111

1212
class UnknownUnitError(ValueError):
1313
def __init__(self, unit: str, locale: Locale):

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ def run(self):
6464
# pytz otherwise does not install on pip 1.4 or
6565
# higher.
6666
'pytz>=2015.7',
67-
'typing_extensions>=4.4.0,<5',
6867
],
6968
cmdclass={'import_cldr': import_cldr},
7069
zip_safe=False,

tox.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ deps =
88
pytest>=6.0
99
pytest-cov
1010
freezegun==0.3.12
11-
typing_extensions>=4.4.0
1211
backports.zoneinfo;python_version<"3.9"
1312
tzdata;sys_platform == 'win32'
1413
whitelist_externals = make

0 commit comments

Comments
 (0)