-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #737 from koxudaxi/support_pydantic_v2_validators_…
…for_232 Support pydantic v2 validators for 232
- Loading branch information
Showing
15 changed files
with
139 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from pydantic import BaseModel, field_validator, model_validator | ||
|
||
def check(func): | ||
def inner(): | ||
func() | ||
return inner | ||
|
||
class A(BaseModel): | ||
a: str | ||
b: str | ||
c: str | ||
d: str | ||
e: str | ||
|
||
@field_validator('a') | ||
def validate_a(<weak_warning descr="Usually first parameter of such methods is named 'cls'">self</weak_warning>): | ||
pass | ||
|
||
@field_validator('b') | ||
def validate_b(<weak_warning descr="Usually first parameter of such methods is named 'cls'">fles</weak_warning>): | ||
pass | ||
|
||
@field_validator('c') | ||
def validate_b(*args): | ||
pass | ||
|
||
@field_validator('d') | ||
def validate_c(**kwargs): | ||
pass | ||
|
||
@field_validator('e') | ||
def validate_e<error descr="Method must have a first parameter, usually called 'cls'">()</error>: | ||
pass | ||
|
||
@model_validator() | ||
def validate_model<error descr="Method must have a first parameter, usually called 'cls'">()</error>: | ||
pass | ||
|
||
|
||
def dummy(self): | ||
pass | ||
|
||
@check | ||
def task(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
def field_validator( | ||
__field: str, | ||
*fields: str, | ||
mode: FieldValidatorModes = 'after', | ||
check_fields: bool | None = None, | ||
) -> Callable[[Any], Any]: | ||
pass | ||
|
||
|
||
def model_validator( | ||
*, | ||
mode: Literal['wrap', 'before', 'after'], | ||
) -> Any: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.