Skip to content

Commit

Permalink
Merge branch 'main' into bump-version-matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
antonagestam authored Sep 15, 2024
2 parents d9bb143 + ebd5f66 commit 8abf489
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 4 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ package_dir =
packages = find:
python_requires = >=3.9
install_requires =
typeguard>=4
# typeguard 4.3.0 breaks "intersection" protocols, see linked issue. I didn't figure
# out a way to work around this at the moment, so it needs to be pinned.
# https://github.com/antonagestam/phantom-types/issues/299
typeguard>=4,<4.3.0
typing_extensions>=4.3.0
numerary>=0.4.3

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 @@ -13,6 +13,7 @@
from typing import cast

import phonenumbers
from typing_extensions import TypeGuard

from phantom import Phantom
from phantom.bounds import parse_str
Expand Down Expand Up @@ -67,7 +68,7 @@ def normalize_phone_number(
is_phone_number = excepts(InvalidPhoneNumber)(_deconstruct_phone_number)


def is_formatted_phone_number(number: str) -> bool:
def is_formatted_phone_number(number: str) -> TypeGuard[FormattedPhoneNumber]:
try:
return number == normalize_phone_number(number)
except InvalidPhoneNumber:
Expand Down
7 changes: 5 additions & 2 deletions tests/ext/test_phonenumbers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from typing_extensions import assert_type

from phantom.errors import BoundError
from phantom.ext.phonenumbers import FormattedPhoneNumber
Expand Down Expand Up @@ -103,8 +104,10 @@ def test_returns_false_for_invalid_number(self):


class TestIsFormattedPhoneNumber:
def test_returns_true_for_formatted_number(self):
assert is_formatted_phone_number("+46123456789") is True
def test_returns_true_for_formatted_number(self) -> None:
value = "+46123456789"
assert is_formatted_phone_number(value)
assert_type(value, FormattedPhoneNumber)

def test_returns_false_for_unformatted_number(self):
assert is_formatted_phone_number("+46 (123) 456 789") is False

0 comments on commit 8abf489

Please sign in to comment.