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 up
Implement Optional required #1031
class Model(BaseModel): nullable: Optional[int] = Field(...)
A benefit is that external libraries using Pydantic like FastAPI or others (and more to come) can create a
Related issue number
@@ 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
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
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!
* Implement Optional required, when creating a ModelField(required=True), make it persist * Add test for nullable required * Improve formatting of Undefined custom object * Refactor field infer/creation with Undefined to make it idempotent Needed for when _type_analysis is re-run in Generics * Add PR changes * Increment/update tests with code review * Update/refactor Undefined implementation with code review * Fix BoolUndefined as string type for mypy, not runtime * Add docs about required Optional * Add explicit tests for Any * Apply code review requested changes * move tests out of test_validators.py