Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ result = validate(data, SCHEMA)
print(result["name"]) # ← IDE が "name" / "level" を補完してくれる
```

注意:
- `collect_errors=True` を指定した場合、`validate` は `ValidationResult` を返します。そのため、`Schema[T]` を使っていても戻り値の型は `T` ではなく `ValidationResult` になります。

TypedDict を書くのが面倒な場合は、既存の辞書スキーマを渡す使い方もそのまま使えます。
型補完が不要なケースでは、変数側に型注釈を書くことで mypy / pyright に型を伝えられます。

Expand Down
2 changes: 1 addition & 1 deletion src/validkit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .v import v
from .validator import validate, ValidationError, Schema

__version__ = "1.1.1"
__version__ = "1.1.0"
__all__ = ["v", "validate", "ValidationError", "Schema"]
44 changes: 40 additions & 4 deletions src/validkit/validator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
from typing import Any, Dict, Generic, List, Optional, TypeVar, overload, TYPE_CHECKING
from typing import (
Any,
Dict,
Generic,
List,
Optional,
TypeVar,
Union,
overload,
TYPE_CHECKING,
Literal,
)
from .v import Validator, v

T = TypeVar("T")
Expand All @@ -18,6 +29,7 @@

SCHEMA: Schema[UserDict] = Schema({"name": v.str(), "age": v.int()})

data: UserDict = {"name": "Alice", "age": 30}
result = validate(data, SCHEMA) # inferred as UserDict by the IDE
print(result["name"]) # IDE completes "name" / "age"
"""
Expand Down Expand Up @@ -165,7 +177,19 @@
partial: bool = ...,
base: Any = ...,
migrate: Optional[Dict[str, Any]] = ...,
collect_errors: bool = ...,
*,
collect_errors: Literal[True],
) -> ValidationResult: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

Copilot Autofix

AI about 14 hours ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.


@overload
def validate(
data: Any,
schema: Schema[T],
partial: bool = ...,
base: Any = ...,
migrate: Optional[Dict[str, Any]] = ...,
*,
collect_errors: Literal[False] = ..., # default
) -> T: ...

@overload
Expand All @@ -175,7 +199,19 @@
partial: bool = ...,
base: Any = ...,
migrate: Optional[Dict[str, Any]] = ...,
collect_errors: bool = ...,
*,
collect_errors: Literal[True],
) -> ValidationResult: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

Copilot Autofix

AI about 14 hours ago

In general, to fix "statement has no effect" warnings where ... is used as a function body, replace the bare ellipsis expression with pass, which is the idiomatic no‑op statement in Python. This keeps the function as a stub without changing behavior.

Here, each overload in the if TYPE_CHECKING: block ends with ) -> ...: .... The ellipsis body is only there as a placeholder, so the best fix is to change ... to pass on each overload definition, including the one on line 204 that CodeQL highlights. This keeps the overloads valid and understandable to type checkers and human readers, while eliminating the no‑effect expression statement. No imports or additional definitions are required.

Concretely, in src/validkit/validator.py, within the if TYPE_CHECKING: block starting around line 171, update all four def validate(...) -> ...: ... overloads so their bodies are pass instead of ....

Suggested changeset 1
src/validkit/validator.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/validkit/validator.py b/src/validkit/validator.py
--- a/src/validkit/validator.py
+++ b/src/validkit/validator.py
@@ -179,7 +179,8 @@
         migrate: Optional[Dict[str, Any]] = ...,
         *,
         collect_errors: Literal[True],
-    ) -> ValidationResult: ...
+    ) -> ValidationResult:
+        pass
 
     @overload
     def validate(
@@ -190,7 +191,8 @@
         migrate: Optional[Dict[str, Any]] = ...,
         *,
         collect_errors: Literal[False] = ...,  # default
-    ) -> T: ...
+    ) -> T:
+        pass
 
     @overload
     def validate(
@@ -201,7 +203,8 @@
         migrate: Optional[Dict[str, Any]] = ...,
         *,
         collect_errors: Literal[True],
-    ) -> ValidationResult: ...
+    ) -> ValidationResult:
+        pass
 
     @overload
     def validate(
@@ -212,7 +215,8 @@
         migrate: Optional[Dict[str, Any]] = ...,
         *,
         collect_errors: Literal[False] = ...,  # default
-    ) -> Any: ...
+    ) -> Any:
+        pass
 
 
 def validate(
EOF
@@ -179,7 +179,8 @@
migrate: Optional[Dict[str, Any]] = ...,
*,
collect_errors: Literal[True],
) -> ValidationResult: ...
) -> ValidationResult:
pass

@overload
def validate(
@@ -190,7 +191,8 @@
migrate: Optional[Dict[str, Any]] = ...,
*,
collect_errors: Literal[False] = ..., # default
) -> T: ...
) -> T:
pass

@overload
def validate(
@@ -201,7 +203,8 @@
migrate: Optional[Dict[str, Any]] = ...,
*,
collect_errors: Literal[True],
) -> ValidationResult: ...
) -> ValidationResult:
pass

@overload
def validate(
@@ -212,7 +215,8 @@
migrate: Optional[Dict[str, Any]] = ...,
*,
collect_errors: Literal[False] = ..., # default
) -> Any: ...
) -> Any:
pass


def validate(
Copilot is powered by AI and may make mistakes. Always verify output.

@overload
def validate(
data: Any,
schema: Any,
partial: bool = ...,
base: Any = ...,
migrate: Optional[Dict[str, Any]] = ...,
*,
collect_errors: Literal[False] = ..., # default
) -> Any: ...


Expand All @@ -186,7 +222,7 @@
base: Any = None,
migrate: Optional[Dict[str, Any]] = None,
collect_errors: bool = False,
) -> Any:
) -> Union[Any, "ValidationResult"]:

# Unwrap Schema[T] to its underlying dict schema
if isinstance(schema, Schema):
Expand Down
Loading