diff --git a/pydantic_extra_types/isbn.py b/pydantic_extra_types/isbn.py index aba89084..27b7fac2 100644 --- a/pydantic_extra_types/isbn.py +++ b/pydantic_extra_types/isbn.py @@ -64,6 +64,17 @@ class Book(BaseModel): @classmethod def __get_pydantic_core_schema__(cls, source: type[Any], handler: GetCoreSchemaHandler) -> core_schema.CoreSchema: + """ + Return a Pydantic CoreSchema with the ISBN validation. + + Args: + source: The source type to be converted. + handler: The handler to get the CoreSchema. + + Returns: + A Pydantic CoreSchema with the ISBN validation. + + """ return core_schema.with_info_before_validator_function( cls._validate, core_schema.str_schema(), @@ -71,13 +82,33 @@ def __get_pydantic_core_schema__(cls, source: type[Any], handler: GetCoreSchemaH @classmethod def _validate(cls, __input_value: str, _: Any) -> str: + """ + Validate a ISBN from the provided str value. + + Args: + __input_value: The str value to be validated. + _: The source type to be converted. + + Returns: + The validated ISBN. + + Raises: + PydanticCustomError: If the ISBN is not valid. + """ cls.validate_isbn_format(__input_value) return cls.convert_isbn10_to_isbn13(__input_value) @staticmethod def validate_isbn_format(value: str) -> None: - """Validate a ISBN format from the provided str value.""" + """Validate a ISBN format from the provided str value. + + Args: + value: The str value to be validated. + + Raises: + PydanticCustomError: If the ISBN is not valid. + """ isbn_length = len(value) @@ -102,8 +133,13 @@ def validate_isbn_format(value: str) -> None: @staticmethod def convert_isbn10_to_isbn13(value: str) -> str: - """ - Convert an ISBN-10 to ISBN-13. + """Convert an ISBN-10 to ISBN-13. + + Args: + value: The ISBN-10 value to be converted. + + Returns: + The converted ISBN-13 value. """ if len(value) == 10: diff --git a/pydantic_extra_types/mac_address.py b/pydantic_extra_types/mac_address.py index 92958e42..ea3548c3 100644 --- a/pydantic_extra_types/mac_address.py +++ b/pydantic_extra_types/mac_address.py @@ -32,6 +32,17 @@ class Network(BaseModel): @classmethod def __get_pydantic_core_schema__(cls, source: type[Any], handler: GetCoreSchemaHandler) -> core_schema.CoreSchema: + """ + Return a Pydantic CoreSchema with the MAC address validation. + + Args: + source: The source type to be converted. + handler: The handler to get the CoreSchema. + + Returns: + A Pydantic CoreSchema with the MAC address validation. + + """ return core_schema.with_info_before_validator_function( cls._validate, core_schema.str_schema(), @@ -39,6 +50,17 @@ def __get_pydantic_core_schema__(cls, source: type[Any], handler: GetCoreSchemaH @classmethod def _validate(cls, __input_value: str, _: Any) -> str: + """ + Validate a MAC Address from the provided str value. + + Args: + __input_value: The str value to be validated. + _: The source type to be converted. + + Returns: + The validated MAC Address. + + """ return cls.validate_mac_address(__input_value.encode()) @staticmethod