Ergonomic handle on arbitrary classes with customised initialization #2543
Unanswered
yoggi-yalla
asked this question in
Question
Replies: 1 comment 2 replies
-
Hi @yoggi-yalla class Delta(relativedelta):
@classmethod
def __get_validators__(cls):
yield cls.validate
@classmethod
def validate(cls, v):
... |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello!
I am currently working in a project where we often use dateutil.relativedelta objects, and I'm struggling to find an ergonomic way of handling them in Pydantic. One requirement is that it should be possible to have a custom init function so that the model can be loaded from string/json. Here's what I came up with:
It kind of does the job, but it's not very neat. An alternative is to put the custom_init validator on every model that uses the frequency, but that would become a bit messy. I hope it makes sense what I'm trying to achieve, does anyone have any suggestions?
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions