Skip to content

Commit ae23fbd

Browse files
📝 docs: improve example formatting in PhoneNumber documentation
1 parent bede935 commit ae23fbd

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

pydantic_extra_types/phone_numbers.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,54 +35,54 @@ class PhoneNumber(str):
3535
### Normal usage:
3636
3737
```python
38-
from pydantic import BaseModel
39-
from pydantic_extra_types.phone_numbers import PhoneNumber
38+
from pydantic import BaseModel
39+
from pydantic_extra_types.phone_numbers import PhoneNumber
4040
41-
class Contact(BaseModel):
42-
name: str
43-
phone: PhoneNumber
41+
class Contact(BaseModel):
42+
name: str
43+
phone: PhoneNumber
4444
45-
c = Contact(name='Alice', phone='+1 650-253-0000')
46-
print(c.phone)
47-
>> tel:+1-650-253-0000 (formatted using RFC3966 by default)
45+
c = Contact(name='Alice', phone='+1 650-253-0000')
46+
print(c.phone)
47+
# > tel:+1-650-253-0000 (formatted using RFC3966 by default)
4848
```
4949
5050
### Changing defaults by subclassing:
5151
5252
```python
53-
from pydantic_extra_types.phone_numbers import PhoneNumber
53+
from pydantic_extra_types.phone_numbers import PhoneNumber
5454
55-
class USPhone(PhoneNumber):
56-
default_region_code = 'US'
57-
supported_regions = ['US']
58-
phone_format = 'NATIONAL'
55+
class USPhone(PhoneNumber):
56+
default_region_code = 'US'
57+
supported_regions = ['US']
58+
phone_format = 'NATIONAL'
5959
60-
# Now parsing will accept national numbers for the US
61-
p = USPhone('650-253-0000')
62-
print(p)
63-
>> 650-253-0000
60+
# Now parsing will accept national numbers for the US
61+
p = USPhone('650-253-0000')
62+
print(p)
63+
# > 650-253-0000
6464
```
6565
6666
### Changing defaults by using the provided validator annotation:
6767
6868
```python
69-
from typing import Annotated, Union
70-
import phonenumbers
71-
from pydantic import BaseModel
72-
from pydantic_extra_types.phone_numbers import PhoneNumberValidator
69+
from typing import Annotated, Union
70+
import phonenumbers
71+
from pydantic import BaseModel
72+
from pydantic_extra_types.phone_numbers import PhoneNumberValidator
7373
74-
E164NumberType = Annotated[
75-
Union[str, phonenumbers.PhoneNumber], PhoneNumberValidator(number_format="E164")
76-
]
74+
E164NumberType = Annotated[
75+
Union[str, phonenumbers.PhoneNumber], PhoneNumberValidator(number_format="E164")
76+
]
7777
7878
79-
class Model(BaseModel):
80-
phone: E164NumberType
79+
class Model(BaseModel):
80+
phone: E164NumberType
8181
8282
83-
m = Model(phone="+1 650-253-0000")
84-
print(m.phone)
85-
>> +16502530000
83+
m = Model(phone="+1 650-253-0000")
84+
print(m.phone)
85+
# > +16502530000
8686
```
8787
8888
"""

0 commit comments

Comments
 (0)