Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement Optional required #1031
Conversation
This comment has been minimized.
This comment has been minimized.
codecov
bot
commented
Nov 26, 2019
•
Codecov Report
@@ Coverage Diff @@
## master #1031 +/- ##
==========================================
- Coverage 100% 99.96% -0.04%
==========================================
Files 20 20
Lines 3316 3332 +16
Branches 653 659 +6
==========================================
+ Hits 3316 3331 +15
- Misses 0 1 +1
Continue to review full report at Codecov.
|
This comment has been minimized.
This comment has been minimized.
This is ready for review @samuelcolvin , @dmontagu . I didn't think the optional nullable was worth extra docs, but let me know if you think this should include some. |
otherwise looking good. |
This comment has been minimized.
This comment has been minimized.
Thanks for the code review! Done |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Sure! |
This comment has been minimized.
This comment has been minimized.
The mypy plugin may need to be changed to reflect this (either it needs to be, or it was a bug before |
This comment has been minimized.
This comment has been minimized.
Thanks @dmontagu ! I haven't been able to check out the mypy plug-in (although I look forward to using it) Should we do the update here or in a separate PR? |
This comment has been minimized.
This comment has been minimized.
I looked at the mypy plugin code and it actually currently treats It would be nice to add tests for this, and I wrote some, but after some reflection I think it will be easiest to just put it in a separate PR (really need to make it easier to write unit tests for the mypy plugin...). I'll take responsibility for writing additional mypy plugin tests, and I'll wait until after this is merged though and we make the desired behavior explicit. I think it would be nice to add some tests here for (Currently the plugin does not treat |
This comment has been minimized.
This comment has been minimized.
Thanks for the review @dmontagu ! I added tests for I guess that will have to be updated if the current behavior is changed. Thanks for taking care of the mypy plug-in! |
This comment has been minimized.
This comment has been minimized.
Thanks for the review, I applied all the requested changes. |
d9bbb05
into
samuelcolvin:master
This comment has been minimized.
This comment has been minimized.
thanks so much, I'll release v1.2 now. |
This comment has been minimized.
This comment has been minimized.
Thanks for fixing the tests I missed And thanks for merging this! |
tiangolo commentedNov 25, 2019
•
edited
Change Summary
Make
ModelField(required=True)
keep the required flag.This allows solving tiangolo/fastapi#646 without hacks, and solves #990, allowing required nullables with:
A benefit is that external libraries using Pydantic like FastAPI or others (and more to come) can create a
ModelField
object, set therequired
argument (ModelField(required=True)
) and expect it to be preserved without having to re-set it after creation withfield.required = True
.Related issue number
#990 #1028
Checklist
changes/<pull request or issue id>-<github username>.md
file added describing change(see changes/README.md for details)