-
-
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
Incompatible type with many=True
#260
Comments
We are observing exactly the same error, in our case we have:
I see that BaseSerializer.instance is annotated as:
That explains why the list is not accepted, even if it is a correct DRF syntax when passing many=True |
I am having the issue with The instance type is returned |
This looks tricky to fix. When
Then an overload should be used here:
To return something Finally, an overload similar to the previous one should be used in the @overload
def __init__(
self,
instance: List[_IN] | None = ...,
data: Any = ...,
partial: Literal[True] = ...,
many: bool = ...,
... But type checkers would probably not be able to infer the returned instance based on the |
I was imagining that we might be able to use an overload here, discriminated on whether |
Made a first draft in the linked PR, I'd be happy to have your insight on it as I'm unsure this would work :) |
I assume this is the related issue on the main repo: encode/django-rest-framework#8926 |
Would it be possible to |
You can check the pending PR #315, |
Right, I suppose the simplest way to get types right is to just call |
Bug report
What's wrong
How is that should be
System information
Linux f16759b1b324 5.10.104-linuxkit #1 SMP PREEMPT Thu Mar 17 17:05:54 UTC 2022 aarch64 GNU/Linux
python
version: 3.10.6django
version: 4.0.7mypy
version: 0.961django-stubs
version: 1.12.0Also, it isn't asked for by the template, but:
djangorestframework
version: 3.13.1djangorestframework-stubs
version: 1.7.0The text was updated successfully, but these errors were encountered: