Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pydantic custom type CronType #22

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

lucianosrp
Copy link
Contributor

I added this on my project and I thought you may want to consider adding it to the core script (?)

It adds a pydantic custom type called CronType.
Which makes it easy to add a Cron object in a pydatic model like below:

>>> from pydantic import BaseModel
... from cron_converter import CronType
...
... class CustomModel(BaseModel):
...     cron: CronType
... 
... model = CustomModel(cron='* * * * *')

>>> model.cron
Cron('* * * * *')

It does not add pydanitc as a core requirement - CronType is made available only if pydantic has been already imported.

Again, not sure if you are willing to integrate this PR or if you would rather have it as a separate extentsion. I am fine either way 🤗

from pydantic import GetPydanticSchema
from pydantic_core import core_schema

CronType = Annotated[
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realised that Annotated requires python>=3.9

There are a couple of ways to solve that.
The best option would be to add typing-extensions for python<=3.8
What do you think?

@Sonic0
Copy link
Owner

Sonic0 commented Sep 18, 2024

@lucianosrp your contributions are always welcome 🤩. I'm unprepared for this topic and I need time to understand your code.
Compatibility with Python 3.8 wouldn't be a problem, just a few weeks and it will be in 'end of life' status.
I need to study something about your code, allow me some time to look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants