pydantic / pydantic-extra-types

Extra Pydantic types.
MIT License
193 stars 51 forks source link

Unable to Import PhoneNumberValidator on Python v3.8 - v3.10 & v3.12 #214

Open hassamsolanomorel opened 1 month ago

hassamsolanomorel commented 1 month ago

Hey team! I've got kinda of a strange one for you.

When trying to use PhoneNumberValidator, as show in the Pydantic documentation example, I keep running into ImportError: cannot import name 'PhoneNumberValidator' from 'pydantic_extra_types.phone_numbers'.

Whats even stranger is I have no such issue importing pydantic_extra_types.phone_numbers.PhoneNumber. I've tried the import statement on several python versions, which I've listed below, and was only able to properly import on version 3.11.3.

My ultimate goal is to replicate NANumber as you have it in your tests almost exactly.

Hoping it's something I'm missing, but wanted to bring this to your attention.

Tested Versions

Python: 3.8.16, 3.9.19, 3.10.15, 3.11.3 (works on this version), 3.12.6 Pydantic: 2.9.1 phonenumbers: 8.13.45

imperosol commented 1 month ago

I ran into the same problem (though I didn't tested on Python 3.11 to see if that resolves the issue). What I found is that PhoneNumberValidator didn't exist at all in the code that was in virtual environment.

So I searched in the real code, on the repo. PhoneNumberValidator does actually exist, but it has been added on August 18th, whereas the last release to PyPI was on July 3rd. The class is documented, but isn't released yet.

I fixed the problem, with poetry, by replacing pydantic-extra-types = "2.9.0" with pydantic-extra-types = { git = "https://github.com/pydantic/pydantic-extra-types.git", rev = "58db4b0" }. I will keep it this way until the release is done.