Conversation
|
just added a test too. |
|
@Gobot1234 please review and let me know if it's in the right direction. |
| from pydantic_core import core_schema | ||
|
|
||
| return core_schema.int_schema(ge=0) | ||
| def validate(value: int) -> "{{ enum.py_name }}": |
There was a problem hiding this comment.
Having a function for each of these adds a lot of bulk to the generated files, can this not go in the original definition for Enum and also be inlined into a lambda as this doesn't need type hints?
There was a problem hiding this comment.
I'm fine with the suggestion. Where do you recommend to declare the validate function? We can also define it as a method in betterproto library too.
There was a problem hiding this comment.
something like
def get_validate_betterproto_enum(cls):
def validate(cls, value):
return cls(value)
return validateThere was a problem hiding this comment.
@Gobot1234 I'm not sure if I understood your suggestion properly actually. At least, I changed to use lambda instead.
Another option is just to define this validator as a class method for class Enum by default.
Please elaborate your suggestion again and I'd be happy to update my PR. Thanks!
Summary
Checklist