Update Field stubs to include None as an input/output type - #511
Open
Kangaroux wants to merge 4 commits into
Open
Update Field stubs to include None as an input/output type#511Kangaroux wants to merge 4 commits into
None as an input/output type#511Kangaroux wants to merge 4 commits into
Conversation
None as an input/output type
Kangaroux
commented
Nov 17, 2023
| NULL_VALUES: set[str | None] | ||
|
|
||
| class CharField(Field[str, str, str, Any]): | ||
| class NullBooleanField(BooleanField): ... |
Author
There was a problem hiding this comment.
It looks like NullBooleanField was deprecated in v3.13 of DRF (and removed in v3.14)
Do you want me to remove it in this PR or make a separate one?
intgr
requested changes
Nov 19, 2023
| NULL_VALUES: set[str | None] | ||
|
|
||
| class CharField(Field[str, str, str, Any]): | ||
| class NullBooleanField(BooleanField): ... |
| class URLField(CharField): ... | ||
|
|
||
| class UUIDField(Field[uuid.UUID, uuid.UUID | str | int, str, Any]): | ||
| class UUIDField(Field[uuid.UUID | None, uuid.UUID | str | int | None, str | None, Any]): |
Contributor
There was a problem hiding this comment.
I don't think this is the best way to go about this.
I suspect not all methods using these typevars can deal with None.
And many places that use these TypeVars already explicitly specify e.g. _VT | None. Seems a lot safer to just update the signatures of the to_representation() method.
Contributor
There was a problem hiding this comment.
Hrm, IntegerField.to_representation() actually does not allow None... Not sure what to make of this.
def to_representation(self, value):
return int(value)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I have made things!
This updates the field stubs to include
Noneas valid input/output. The only projects that should be impacted by this change are those using serializer fields directly which I imagine are a very small minority. SinceBaseSerializeris a subclass ofFieldbut usesAnyas the input/output types, the serializer stubs should remain unchanged.Related issues