Initial implementation of ConstrainedDate, condate#3740
Initial implementation of ConstrainedDate, condate#3740samuelcolvin merged 15 commits intopydantic:masterfrom
Conversation
|
seems like using Would appreciate some guidance on whether this approach makes sense and how to add necessary changes to _hypothesis_plugin.py |
@Zac-HD any ideas? |
Zac-HD
left a comment
There was a problem hiding this comment.
Suggested fix below, though I haven't tested it. I'd also recommend renaming the class ConstrainedScalarMeta, because a date (or datetime) is definitely not a number.
Co-authored-by: Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
|
Unsubscribing because this looks like standard "read CI logs and fix errors" territory; ping me again if you have a Hypothesis question. |
|
Thanks for the help and changes, I've now got initial version working and all tests pass. Some follow up questions for @samuelcolvin
Thanks! |
|
please review |
samuelcolvin
left a comment
There was a problem hiding this comment.
Looking good, some things to change.
| ### Arguments to `condate` | ||
| The following arguments are available when using the `condate` type function | ||
|
|
||
| - `strict_formats: List[str] = None`: list of datetime.datetime.strpformat style date formats that will be accepted |
There was a problem hiding this comment.
Let's remove this, it's not supported in V2 so it'll be confusing if we add it now in V1.
(the bounds constraints are already implemented in V2).
| if TYPE_CHECKING: | ||
| PastDate = date | ||
| FutureDate = date | ||
| PastDate = datetime.date |
There was a problem hiding this comment.
Best to revert these changes.
| @@ -0,0 +1,75 @@ | |||
| from datetime import date, datetime | |||
There was a problem hiding this comment.
can you move this into test_datetime_parse.py, We could do with rearranging tests, putting some tests in this file will cause more confusion.
| update_not_none(field_schema, exclusiveMinimum=cls.gt, exclusiveMaximum=cls.lt, minimum=cls.ge, maximum=cls.le) | ||
|
|
||
| @classmethod | ||
| def strict_date_validator(cls, value: Any) -> datetime.date: |
There was a problem hiding this comment.
as per my above comment, remove this.
|
please update. |
|
you'll also need to rebase or merge master to get all a green tick. |
|
Hopefully that covers everything you mentioned :) Sorry if some of this overlaps with changes already envisioned for V2 And thanks for the great work! |
samuelcolvin
left a comment
There was a problem hiding this comment.
Looking good but a few more things to fix.
… schema_json, add hypothesis test, etc
|
Hopefully nearly there now :) |
|
this is great, thank you so much. |
Change Summary
Initial implementation of ConstrainedDate, condate, with tests and docs
ConstrainedDate piggybacks off
ConstrainedNumberMetaandnumber_size_validatorto implement the gt/ge/lt/le logicPerhaps those should be renamed to hint that they are not just applicable to numbers?
if accepted, more doc changes will be needed to highlight that date validation can be constrained
also if accepted suggest similar classes for datetime, time may be needed?
Many thanks for great library!
(p.s. I replaced date with datetime.date throughout types.py to avoid inevitable confusion that otherwise arises between datetime module vs datetime class)
Related issue number
fix #3739
Checklist
changes/<pull request or issue id>-<github username>.mdfile added describing change(see changes/README.md for details)