diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1bbdc67..52cedf4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v5.0.0 hooks: - id: no-commit-to-branch # prevent direct commits to the `main` branch - id: check-yaml @@ -24,3 +24,10 @@ repos: types: [python] language: system pass_filenames: false + - id: Typecheck + name: Typecheck + entry: make + args: [typecheck] + types: [python] + language: system + pass_filenames: false diff --git a/Makefile b/Makefile index 9c49a64..5f7f05c 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,10 @@ lint: uv run ruff format --check uv run ruff check +.PHONY: typecheck # Typecheck the code +typecheck: + uv run mypy pydantic_extra_types + .PHONY: test test: uv run pytest diff --git a/pydantic_extra_types/domain.py b/pydantic_extra_types/domain.py index 1e44ebb..6640de6 100644 --- a/pydantic_extra_types/domain.py +++ b/pydantic_extra_types/domain.py @@ -54,4 +54,5 @@ def __get_pydantic_core_schema__(cls, source_type: Any, handler: GetCoreSchemaHa def __get_pydantic_json_schema__( cls, schema: core_schema.CoreSchema, handler: GetCoreSchemaHandler ) -> dict[str, Any]: - return handler(schema) + # Cast the return value to dict[str, Any] + return dict(handler(schema)) diff --git a/pydantic_extra_types/phone_numbers.py b/pydantic_extra_types/phone_numbers.py index ca1ccb9..880446f 100644 --- a/pydantic_extra_types/phone_numbers.py +++ b/pydantic_extra_types/phone_numbers.py @@ -90,7 +90,7 @@ class PhoneNumberValidator: supported_regions (list[str]): The supported regions. If empty, all regions are supported (default). Returns: - str: The formatted phone number. + The formatted phone number. Example: MyNumberType = Annotated[ diff --git a/pydantic_extra_types/semantic_version.py b/pydantic_extra_types/semantic_version.py index 1da3f83..8ffdfde 100644 --- a/pydantic_extra_types/semantic_version.py +++ b/pydantic_extra_types/semantic_version.py @@ -53,3 +53,7 @@ def __get_pydantic_json_schema__( pattern=r'^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$' ) ) + + @classmethod + def validate_from_str(cls, value: str) -> 'SemanticVersion': + return cls.parse(value)