-
-
Notifications
You must be signed in to change notification settings - Fork 121
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
Update Field stubs to include None
as an input/output type
#511
base: master
Are you sure you want to change the base?
Conversation
None
as an input/output type
Any, | ||
] | ||
): | ||
TRUE_VALUES: set[str | bool | int] | ||
FALSE_VALUES: set[str | bool | int | float] | ||
NULL_VALUES: set[str | None] | ||
|
||
class CharField(Field[str, str, str, Any]): | ||
class NullBooleanField(BooleanField): ... |
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.
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?
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.
Separate PR please.
Any, | ||
] | ||
): | ||
TRUE_VALUES: set[str | bool | int] | ||
FALSE_VALUES: set[str | bool | int | float] | ||
NULL_VALUES: set[str | None] | ||
|
||
class CharField(Field[str, str, str, Any]): | ||
class NullBooleanField(BooleanField): ... |
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.
Separate PR please.
@@ -227,7 +217,7 @@ class SlugField(CharField): | |||
|
|||
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]): |
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 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.
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.
Hrm, IntegerField.to_representation()
actually does not allow None
... Not sure what to make of this.
def to_representation(self, value):
return int(value)
I have made things!
This updates the field stubs to include
None
as 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. SinceBaseSerializer
is a subclass ofField
but usesAny
as the input/output types, the serializer stubs should remain unchanged.Related issues