-
Notifications
You must be signed in to change notification settings - Fork 318
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
Phonenumber field difference for Python 2 and 3 #136
Comments
Yes I have the same issue, it seems this was not resolved. |
Please consider following script: import phonenumbers
from django.conf import settings
from phonenumber_field.phonenumber import PhoneNumber, to_python
settings.configure(PHONENUMBER_DEFAULT_REGION='PH')
assert str(to_python('none')) == '+NoneNone'
assert str(to_python('None')) == '+NoneNone'
assert str(to_python('9581093')) == '+639581093'
assert str(PhoneNumber.from_string(phone_number='123')) == '+63123' I've run it successfully on both python 2.7.12 and python 3.6.5 with django-phonenumber-field 2.0.0 installed. So I couldn't reproduce your issue. |
In my very first post I wrote exact version of python and django-phonenumber-field used 😉. To be even more specific: Successful casespython2
python3
Unsuccessful casespython2
python3
My bottom line is it not related with version of python or Django or phonenumbers*. It was a change between django-phonenumber-field version 1.0.0 and 1.1.0. Therefore there is noting to fix. I think there is no reasonable output for those inputs. This library is very lenient... perhaps too much. I would rise |
HI @amateja Where did you modify this is it inside your library or I need to create a new class. import phonenumbers from phonenumber_field.phonenumber import PhoneNumber, to_python settings.configure(PHONENUMBER_DEFAULT_REGION='PH') assert str(to_python('none')) == '+NoneNone' |
This is a standalone script not a copy-paste solution for your problem. If you use django-phonenumber-field in version 1.0.0 you get To test my theses please just launch your python interpreter and copy-paste this sample code. If you find I'm wrong please attach output of this script and add result of |
HI, I had this figured out, Thank you for this! |
Glad I could help. Cheers! |
Hi Guys,
Just a quick question.. why is that for Python 2, if the phone number is invalid it just returns the raw input while in Python 3, it converts it to either +NoneNone or +63(region code, mine is PH)(Raw Input) ?
Below are what i have tried.
Python2
print to_python('none') - none
print to_python('None') - None
print to_python('9581093') - 9581093
print PhoneNumber.from_string(phone_number='123') - 123
Python3
print(to_python('none')) - +NoneNone
print(to_python('None')) - +NoneNone
print(to_python('9581093')) - +639581093
print(PhoneNumber.from_string(phone_number='213')) - +63213
The text was updated successfully, but these errors were encountered: