Skip to content

Commit

Permalink
fix: Use explicit TypeAlias throughout (#292)
Browse files Browse the repository at this point in the history
Closes #272.
  • Loading branch information
antonagestam committed Dec 10, 2023
1 parent 5998186 commit 7ae8fcc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/phantom/_utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from typing import Tuple
from typing import Union

from typing_extensions import TypeAlias
from typing_extensions import TypeGuard
from typing_extensions import get_args
from typing_extensions import get_origin
Expand All @@ -38,7 +39,7 @@ def resolve_class_attr(
)


BoundType = Union[type, Tuple[type, ...]]
BoundType: TypeAlias = Union[type, Tuple[type, ...]]


def _is_union(type_: BoundType) -> bool:
Expand Down
3 changes: 2 additions & 1 deletion src/phantom/ext/phonenumbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def _deconstruct_phone_number(


def normalize_phone_number(
phone_number: str, country_code: str | None = None
phone_number: str,
country_code: str | None = None,
) -> FormattedPhoneNumber:
"""
Normalize ``phone_number`` using :py:const:`phonenumbers.PhoneNumberFormat.E164`.
Expand Down
7 changes: 4 additions & 3 deletions src/phantom/iso3166.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from typing import Union
from typing import cast

from typing_extensions import TypeAlias
from typing_extensions import get_args

from phantom import Phantom
Expand All @@ -33,7 +34,7 @@
"InvalidCountryCode",
)

LiteralAlpha2 = Literal[
LiteralAlpha2: TypeAlias = Literal[
"AF",
"AX",
"AL",
Expand Down Expand Up @@ -334,5 +335,5 @@ def __register_strategy__(cls) -> _hypothesis.SearchStrategy | None:
return sampled_from(sorted(ALPHA2))


Alpha2 = Union[LiteralAlpha2, ParsedAlpha2]
CountryCode = Alpha2
Alpha2: TypeAlias = Union[LiteralAlpha2, ParsedAlpha2]
CountryCode: TypeAlias = Alpha2
4 changes: 3 additions & 1 deletion src/phantom/predicates/_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import Callable
from typing import TypeVar

from typing_extensions import TypeAlias

T_contra = TypeVar("T_contra", bound=object, contravariant=True)

Predicate = Callable[[T_contra], bool]
Predicate: TypeAlias = Callable[[T_contra], bool]

0 comments on commit 7ae8fcc

Please sign in to comment.