keleshev / schema

Schema validation just got Pythonic
MIT License
2.86k stars 214 forks source link

Hook() breaks on custom handler #294

Open cdeckard opened 1 year ago

cdeckard commented 1 year ago

Perhaps i'm using it wrong, but: str: { Hook('my_key', handler=my_handler): str, 'another_key': str }

breaks. this is due to the lack of processing and break statement when the handler returns at line 402. Perhaps i should use a class instead of handler function (I didn't look into this) 😺. As for now, I fixed it by adding:

skey.handler(nkey, data, e)
   try:
       nvalue = Schema(svalue, error=e, ignore_extra_keys=i).validate(value, **kwargs)
   except SchemaError as x:
       k = "Key '%s' error:" % nkey
       message = self._prepend_schema_name(k)
       raise SchemaError([message] + x.autos,
                         [e.format(data) if e else None] + x.errors)
   else:
       new[nkey] = nvalue
       coverage.add(skey)
       break