Use TypeAlias where possible for type aliases (#7630)

This commit is contained in:
Alex Waygood
2022-04-16 02:01:00 +01:00
committed by GitHub
parent c0e6dd3f3f
commit 740193a8fc
218 changed files with 760 additions and 625 deletions

View File

@@ -1,5 +1,5 @@
from typing import Any
from typing_extensions import Literal
from typing_extensions import Literal, TypeAlias
class UnknownLocaleError(Exception):
identifier: Any
@@ -115,7 +115,7 @@ def parse_locale(identifier, sep: str = ...): ...
def get_locale_identifier(tup, sep: str = ...): ...
def get_global(key: _GLOBAL_KEY): ...
_GLOBAL_KEY = Literal[
_GLOBAL_KEY: TypeAlias = Literal[
"all_currencies",
"currency_fractions",
"language_aliases",

View File

@@ -1,6 +1,6 @@
from datetime import date, datetime, time, timedelta, tzinfo
from typing import Any, overload
from typing_extensions import Literal
from typing_extensions import Literal, TypeAlias
from babel.core import Locale
from babel.util import LOCALTZ as LOCALTZ, UTC as UTC
@@ -10,8 +10,8 @@ from pytz import BaseTzInfo
# http://babel.pocoo.org/en/latest/api/dates.html
# Date and Time Formatting
_Instant = date | time | datetime | float | None
_PredefinedTimeFormat = Literal["full", "long", "medium", "short"]
_Instant: TypeAlias = date | time | datetime | float | None
_PredefinedTimeFormat: TypeAlias = Literal["full", "long", "medium", "short"]
def format_datetime(
datetime: _Instant = ..., format: _PredefinedTimeFormat | str = ..., tzinfo: tzinfo | None = ..., locale: str | Locale = ...
@@ -57,7 +57,7 @@ def get_timezone_gmt(
return_z: bool = ...,
) -> str: ...
_DtOrTzinfo = datetime | tzinfo | str | int | time | None
_DtOrTzinfo: TypeAlias = datetime | tzinfo | str | int | time | None
def get_timezone_location(dt_or_tzinfo: _DtOrTzinfo = ..., locale: str | Locale = ..., return_city: bool = ...) -> str: ...
def get_timezone_name(