Skip to content

Commit 8520b17

Browse files
committed
Fix various documentation layout issues
1 parent d18df25 commit 8520b17

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

pydantic_extra_types/pendulum_dt.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,8 @@ def to_iso8601_string(self) -> str:
200200
201201
In addition to the standard ISO 8601 format, this method also supports the representation of fractions of a second and negative durations.
202202
203-
Args:
204-
duration (Duration): The Duration object.
205-
206203
Returns:
207-
str: The ISO 8601 string representation of the duration.
204+
The ISO 8601 string representation of the duration.
208205
"""
209206
# Extracting components from the Duration object
210207
years = self.years

pydantic_extra_types/phone_numbers.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""The `pydantic_extra_types.phone_numbers` module provides the
22
[`PhoneNumber`][pydantic_extra_types.phone_numbers.PhoneNumber] data type.
33
4-
This class depends on the [phonenumbers] package, which is a Python port of Google's [libphonenumber].
4+
This class depends on the [phonenumbers](https://pypi.orgt/phonenumbers/) package,
5+
which is a Python port of Google's [libphonenumber](https://github.com/google/libphonenumber/).
56
"""
67

78
from __future__ import annotations
@@ -25,15 +26,14 @@
2526

2627

2728
class PhoneNumber(str):
28-
"""A wrapper around [phonenumbers](https://pypi.org/project/phonenumbers/) package, which
29-
is a Python port of Google's [libphonenumber](https://github.com/google/libphonenumber/).
30-
"""
31-
32-
supported_regions: list[str] = []
33-
"""The supported regions. If empty, all regions are supported."""
29+
"""A wrapper around the `phonenumbers.PhoneNumber` object."""
3430

3531
default_region_code: ClassVar[str | None] = None
3632
"""The default region code to use when parsing phone numbers without an international prefix."""
33+
34+
supported_regions: list[str] = []
35+
"""The supported regions. If empty, all regions are supported."""
36+
3737
phone_format: str = 'RFC3966'
3838
"""The format of the phone number."""
3939

@@ -78,38 +78,40 @@ def __hash__(self) -> int:
7878

7979
@dataclass(frozen=True)
8080
class PhoneNumberValidator:
81-
"""A pydantic before validator for phone numbers using the [phonenumbers](https://pypi.org/project/phonenumbers/) package,
82-
a Python port of Google's [libphonenumber](https://github.com/google/libphonenumber/).
81+
"""An annotation to validate `phonenumbers.PhoneNumber` objects.
8382
84-
Intended to be used to create custom pydantic data types using the `typing.Annotated` type construct.
83+
Example:
84+
```python
85+
from typing import Annotated, Union
8586
86-
Args:
87-
default_region (str | None): The default region code to use when parsing phone numbers without an international prefix.
88-
If `None` (default), the region must be supplied in the phone number as an international prefix.
89-
number_format (str): The format of the phone number to return. See `phonenumbers.PhoneNumberFormat` for valid values.
90-
supported_regions (list[str]): The supported regions. If empty, all regions are supported (default).
87+
import phonenumbers
88+
from pydantic import BaseModel
89+
from pydantic_extra_types.phone_numbers import PhoneNumberValidator
9190
92-
Returns:
93-
The formatted phone number.
91+
MyNumberType = Annotated[Union[str, phonenumbers.PhoneNumber], PhoneNumberValidator()]
9492
95-
Example:
96-
MyNumberType = Annotated[
97-
Union[str, phonenumbers.PhoneNumber],
98-
PhoneNumberValidator()
99-
]
10093
USNumberType = Annotated[
101-
Union[str, phonenumbers.PhoneNumber],
102-
PhoneNumberValidator(supported_regions=['US'], default_region='US')
94+
Union[str, phonenumbers.PhoneNumber], PhoneNumberValidator(supported_regions=['US'], default_region='US')
10395
]
10496
97+
10598
class SomeModel(BaseModel):
10699
phone_number: MyNumberType
107100
us_number: USNumberType
101+
```
108102
"""
109103

110104
default_region: str | None = None
105+
"""The default region code to use when parsing phone numbers without an international prefix.
106+
107+
If `None` (the default), the region must be supplied in the phone number as an international prefix.
108+
"""
109+
111110
number_format: str = 'RFC3966'
111+
"""The format of the phone number to return. See `phonenumbers.PhoneNumberFormat` for valid values."""
112+
112113
supported_regions: Sequence[str] | None = None
114+
"""The supported regions. If empty (the default), all regions are supported."""
113115

114116
def __post_init__(self) -> None:
115117
if self.default_region and self.default_region not in phonenumbers.SUPPORTED_REGIONS:

0 commit comments

Comments
 (0)