Skip to content

Commit 5ded2a1

Browse files
authored
✨ Add type checking support (#285)
* ✨ Add type checking support and improve type hints across the codebase * 🔧 Remove type ignores for improved type checking in Pendulum and Semantic Version classes
1 parent 01866e6 commit 5ded2a1

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.3.0
3+
rev: v5.0.0
44
hooks:
55
- id: no-commit-to-branch # prevent direct commits to the `main` branch
66
- id: check-yaml
@@ -24,3 +24,10 @@ repos:
2424
types: [python]
2525
language: system
2626
pass_filenames: false
27+
- id: Typecheck
28+
name: Typecheck
29+
entry: make
30+
args: [typecheck]
31+
types: [python]
32+
language: system
33+
pass_filenames: false

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ lint:
2525
uv run ruff format --check
2626
uv run ruff check
2727

28+
.PHONY: typecheck # Typecheck the code
29+
typecheck:
30+
uv run mypy pydantic_extra_types
31+
2832
.PHONY: test
2933
test:
3034
uv run pytest

pydantic_extra_types/domain.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,5 @@ def __get_pydantic_core_schema__(cls, source_type: Any, handler: GetCoreSchemaHa
5454
def __get_pydantic_json_schema__(
5555
cls, schema: core_schema.CoreSchema, handler: GetCoreSchemaHandler
5656
) -> dict[str, Any]:
57-
return handler(schema)
57+
# Cast the return value to dict[str, Any]
58+
return dict(handler(schema))

pydantic_extra_types/phone_numbers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class PhoneNumberValidator:
9090
supported_regions (list[str]): The supported regions. If empty, all regions are supported (default).
9191
9292
Returns:
93-
str: The formatted phone number.
93+
The formatted phone number.
9494
9595
Example:
9696
MyNumberType = Annotated[

pydantic_extra_types/semantic_version.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,7 @@ def __get_pydantic_json_schema__(
5353
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-]+)*))?$'
5454
)
5555
)
56+
57+
@classmethod
58+
def validate_from_str(cls, value: str) -> 'SemanticVersion':
59+
return cls.parse(value)

0 commit comments

Comments
 (0)