Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhoneNumberType().python_type should be a class #248

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions sqlalchemy_utils/types/phone_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ class User(self.Base):
STORE_FORMAT = 'e164'
impl = types.Unicode(20)

def python_type(self, text):
return self._coerce(text)
@property
def python_type(self):
return PhoneNumber

def __init__(self, region='US', max_length=20, *args, **kwargs):
# Bail if phonenumbers is not found.
Expand Down
4 changes: 4 additions & 0 deletions tests/types/test_phonenumber.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ def test_scalar_attributes_get_coerced_to_objects(self, User):

assert isinstance(user.phone_number, PhoneNumber)

def test_can_get_python_type(self):
pn_type = PhoneNumberType()
assert pn_type.python_type is PhoneNumber


@pytest.mark.skipif('types.phone_number.phonenumbers is None')
class TestPhoneNumberComposite(object):
Expand Down