Skip to content

Commit 1c69d4c

Browse files
committed
Un-shadow types in support
1 parent 0f78ea8 commit 1c69d4c

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

babel/support.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"""
1313
from __future__ import annotations
1414

15-
import decimal
1615
import gettext
1716
import locale
1817
import os
@@ -31,6 +30,9 @@
3130
)
3231

3332
if TYPE_CHECKING:
33+
import datetime as _datetime
34+
from decimal import Decimal
35+
3436
from typing_extensions import Literal
3537

3638
from babel.dates import _PredefinedTimeFormat
@@ -52,7 +54,7 @@ class Format:
5254
def __init__(
5355
self,
5456
locale: Locale | str,
55-
tzinfo: datetime.tzinfo | None = None,
57+
tzinfo: _datetime.tzinfo | None = None,
5658
*,
5759
numbering_system: Literal["default"] | str = "latn",
5860
) -> None:
@@ -69,7 +71,7 @@ def __init__(
6971

7072
def date(
7173
self,
72-
date: datetime.date | None = None,
74+
date: _datetime.date | None = None,
7375
format: _PredefinedTimeFormat | str = 'medium',
7476
) -> str:
7577
"""Return a date formatted according to the given pattern.
@@ -83,7 +85,7 @@ def date(
8385

8486
def datetime(
8587
self,
86-
datetime: datetime.date | None = None,
88+
datetime: _datetime.date | None = None,
8789
format: _PredefinedTimeFormat | str = 'medium',
8890
) -> str:
8991
"""Return a date and time formatted according to the given pattern.
@@ -98,7 +100,7 @@ def datetime(
98100

99101
def time(
100102
self,
101-
time: datetime.time | datetime.datetime | None = None,
103+
time: _datetime.time | _datetime.datetime | None = None,
102104
format: _PredefinedTimeFormat | str = 'medium',
103105
) -> str:
104106
"""Return a time formatted according to the given pattern.
@@ -113,7 +115,7 @@ def time(
113115

114116
def timedelta(
115117
self,
116-
delta: datetime.timedelta | int,
118+
delta: _datetime.timedelta | int,
117119
granularity: Literal["year", "month", "week", "day", "hour", "minute", "second"] = "second",
118120
threshold: float = 0.85,
119121
format: Literal["narrow", "short", "medium", "long"] = "long",
@@ -131,7 +133,7 @@ def timedelta(
131133
format=format, add_direction=add_direction,
132134
locale=self.locale)
133135

134-
def number(self, number: float | decimal.Decimal | str) -> str:
136+
def number(self, number: float | Decimal | str) -> str:
135137
"""Return an integer number formatted for the locale.
136138
137139
>>> fmt = Format('en_US')
@@ -140,7 +142,7 @@ def number(self, number: float | decimal.Decimal | str) -> str:
140142
"""
141143
return format_decimal(number, locale=self.locale, numbering_system=self.numbering_system)
142144

143-
def decimal(self, number: float | decimal.Decimal | str, format: str | None = None) -> str:
145+
def decimal(self, number: float | Decimal | str, format: str | None = None) -> str:
144146
"""Return a decimal number formatted for the locale.
145147
146148
>>> fmt = Format('en_US')
@@ -151,7 +153,7 @@ def decimal(self, number: float | decimal.Decimal | str, format: str | None = No
151153

152154
def compact_decimal(
153155
self,
154-
number: float | decimal.Decimal | str,
156+
number: float | Decimal | str,
155157
format_type: Literal['short', 'long'] = 'short',
156158
fraction_digits: int = 0,
157159
) -> str:
@@ -171,14 +173,14 @@ def compact_decimal(
171173
numbering_system=self.numbering_system,
172174
)
173175

174-
def currency(self, number: float | decimal.Decimal | str, currency: str) -> str:
176+
def currency(self, number: float | Decimal | str, currency: str) -> str:
175177
"""Return a number in the given currency formatted for the locale.
176178
"""
177179
return format_currency(number, currency, locale=self.locale, numbering_system=self.numbering_system)
178180

179181
def compact_currency(
180182
self,
181-
number: float | decimal.Decimal | str,
183+
number: float | Decimal | str,
182184
currency: str,
183185
format_type: Literal['short'] = 'short',
184186
fraction_digits: int = 0,
@@ -192,7 +194,7 @@ def compact_currency(
192194
return format_compact_currency(number, currency, format_type=format_type, fraction_digits=fraction_digits,
193195
locale=self.locale, numbering_system=self.numbering_system)
194196

195-
def percent(self, number: float | decimal.Decimal | str, format: str | None = None) -> str:
197+
def percent(self, number: float | Decimal | str, format: str | None = None) -> str:
196198
"""Return a number formatted as percentage for the locale.
197199
198200
>>> fmt = Format('en_US')
@@ -201,7 +203,7 @@ def percent(self, number: float | decimal.Decimal | str, format: str | None = No
201203
"""
202204
return format_percent(number, format, locale=self.locale, numbering_system=self.numbering_system)
203205

204-
def scientific(self, number: float | decimal.Decimal | str) -> str:
206+
def scientific(self, number: float | Decimal | str) -> str:
205207
"""Return a number formatted using scientific notation for the locale.
206208
"""
207209
return format_scientific(number, locale=self.locale, numbering_system=self.numbering_system)
@@ -389,7 +391,7 @@ def __init__(self, fp: gettext._TranslationsReader | None = None) -> None:
389391
# is parsed (fp != None). Ensure that they are always present because
390392
# some *gettext methods (including '.gettext()') rely on the attributes.
391393
self._catalog: dict[tuple[str, Any] | str, str] = {}
392-
self.plural: Callable[[float | decimal.Decimal], int] = lambda n: int(n != 1)
394+
self.plural: Callable[[float | Decimal], int] = lambda n: int(n != 1)
393395
super().__init__(fp=fp)
394396
self.files = list(filter(None, [getattr(fp, 'name', None)]))
395397
self.domain = self.DEFAULT_DOMAIN

0 commit comments

Comments
 (0)