-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add PastDatetime and FutureDatetime types #5720
Conversation
Deploying with Cloudflare Pages
|
Please review |
pydantic/types.py
Outdated
return core_schema.datetime_schema(now_op='past') | ||
else: | ||
schema = handler(source) | ||
assert schema['type'] == 'datetime' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this assertion? If there's a chance it could be hit, it may be worth giving a clearer message of what is going wrong if it does get hit. (Same for FutureDatetime below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I don't know how to hit this line. I just keep it because it was in the other types(AwareDatetime
, FutureDate
, ...).
@samuelcolvin Do you have any idea here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the assert would fail if you use it as an annotation on something other than datetime
.
If I'm wrong, we can remove, otherwise, yes a better error would be good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a check that raises an error. added doc and test for error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made some suggestions above; feel free to take or leave
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherwise LGTM.
please update.
docs/usage/types/datetime.md
Outdated
@@ -23,6 +23,12 @@ types: | |||
`FutureDate` | |||
: like `date`, but the date should be in the future | |||
|
|||
`PastDatetime` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
surely we shouldn't have these documented in two places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed from here
pydantic/types.py
Outdated
return core_schema.datetime_schema(now_op='past') | ||
else: | ||
schema = handler(source) | ||
assert schema['type'] == 'datetime' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the assert would fail if you use it as an annotation on something other than datetime
.
If I'm wrong, we can remove, otherwise, yes a better error would be good.
c0f9628
to
15f1549
Compare
15f1549
to
74b3b58
Compare
@samuelcolvin I've addressed all the comments. Please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherwise lGTM.
Error documentation will come later with the validation error docs PR
Selected Reviewer: @samuelcolvin