1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
from pydantic import BaseModel
class MyModel(BaseModel):
x: int
m = MyModel(x='10')
if m.x != 10:
raise ValueError('m.x should be 10')
log = []
class ValidatePythonHandler:
def on_enter(self, *args, **kwargs) -> None:
log.append(f'on_enter args={args} kwargs={kwargs}')
def on_success(self, result) -> None:
log.append(f'on_success result={result}')
def on_error(self, error) -> None:
log.append(f'on_error error={error}')
class Plugin:
def new_schema_validator(self, schema, schema_type, schema_type_path, schema_kind, config, plugin_settings):
return ValidatePythonHandler(), None, None
plugin = Plugin()
|