-
-
Notifications
You must be signed in to change notification settings - Fork 127
Add CurrentUserDefault #19
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
Conversation
rest_framework-stubs/fields.pyi
Outdated
@@ -39,6 +39,10 @@ class CreateOnlyDefault(object): | |||
def set_context(self, serializer_field: Field) -> None: ... | |||
def __call__(self) -> Any: ... | |||
|
|||
class CurrentUserDefault(object): | |||
def set_context(self, serializer_field: Field) -> None: ... | |||
def __call__(self) -> 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.
@mkurnikov are we okay with Any
in these cases?
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.
Sorry, I somehow missed it. Just add some # TODO:
for later, with explanation why it's difficult to add return type now, and it's good to go.
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 pushed a change to make it Union[AnonymousUser, User]
which is what get_user returns. This assumes both AuthenticationMiddleware
is used and there's no custom user model in use.
f7571e9
to
c0e28ce
Compare
This should had be merged now, sorry for the long delay! P.S. facing the same issue right now:
|
It has actually changed is the most recent version of drf. Now it is: # TODO: fix when drf-stubs > 1.1 will be released
class _CurrentAppUserDefault(fields.CurrentUserDefault): # type: ignore
def __call__(self, serializer_field):
return serializer_field.context['request'].user.link.profile But again, we need to understand how to work with different versions of annotations. |
@sobolevn I've created one here python/typing#693 |
No description provided.