From c54f5584606f215d919ebcb15602ff6b8d04bf71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Freitag?= Date: Thu, 8 Sep 2022 15:54:54 +0200 Subject: [PATCH] Use attributes and methods from phonenumbers Instead of loading from the submodules, keep to the phonenumbers module. That avoids prying into its implementation. --- phonenumber_field/phonenumber.py | 7 ++----- phonenumber_field/widgets.py | 2 +- tests/tests.py | 9 +++------ 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/phonenumber_field/phonenumber.py b/phonenumber_field/phonenumber.py index d31d8a01..e8a579f8 100644 --- a/phonenumber_field/phonenumber.py +++ b/phonenumber_field/phonenumber.py @@ -157,11 +157,8 @@ def to_python(value, region=None): def validate_region(region): - if ( - region is not None - and region not in phonenumbers.phonenumberutil.SUPPORTED_REGIONS - ): + if region is not None and region not in phonenumbers.SUPPORTED_REGIONS: raise ValueError( "ā€œ%sā€ is not a valid region code. Choices are %r" - % (region, phonenumbers.phonenumberutil.SUPPORTED_REGIONS) + % (region, phonenumbers.SUPPORTED_REGIONS) ) diff --git a/phonenumber_field/widgets.py b/phonenumber_field/widgets.py index 847f4499..655eaf19 100644 --- a/phonenumber_field/widgets.py +++ b/phonenumber_field/widgets.py @@ -6,7 +6,7 @@ from django.forms import Select, TextInput from django.forms.widgets import MultiWidget from django.utils import translation -from phonenumbers.phonenumberutil import ( +from phonenumbers import ( COUNTRY_CODE_TO_REGION_CODE, national_significant_number, region_code_for_number, diff --git a/tests/tests.py b/tests/tests.py index 2aedeae4..3462af38 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -4,7 +4,6 @@ from django.db.models import Model from django.test import SimpleTestCase, TestCase, override_settings from django.utils.encoding import force_str -from phonenumbers import phonenumberutil from phonenumber_field import formfields, modelfields from phonenumber_field.phonenumber import PhoneNumber, to_python @@ -129,9 +128,7 @@ def test_null_field_returns_none(self): self.assertIsNone(model.phone_number) model.phone_number = self.test_number_1 self.assertIsInstance(model.phone_number, PhoneNumber) - model.phone_number = phonenumberutil.parse( - self.test_number_1, keep_raw_input=True - ) + model.phone_number = phonenumbers.parse(self.test_number_1, keep_raw_input=True) self.assertIsInstance(model.phone_number, PhoneNumber) def test_can_assign_string_phone_number(self): @@ -149,10 +146,10 @@ def test_can_assign_string_phone_number(self): def test_can_assign_phonenumber(self): """ - Tests assignment phonenumberutil.PhoneNumber to field + Tests assignment phonenumbers.PhoneNumber to field """ opt_phone = models.OptionalPhoneNumber() - opt_phone.phone_number = phonenumberutil.parse( + opt_phone.phone_number = phonenumbers.parse( self.test_number_1, keep_raw_input=True ) self.assertIsInstance(opt_phone.phone_number, PhoneNumber)