-
-
Notifications
You must be signed in to change notification settings - Fork 494
[typing BUG] PatchDict
Type checking error
#1441
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
Comments
PatchDict
usage Type error PatchDict
Type checking error
@sxoinas12 could you share what do you use for typechecing (exact version and command you are running to type check it ? ) |
@vitalik Thanks for coming back to this . I am using
simply by running |
PatchDict
Type checking error PatchDict
Type checking error
This is also reproducible with the upstream pyright using its latest version (1.1.400) with the configuration |
@Ige-kun @sxoinas12 - can you check if placing this before you code will work ? from typing import TYPE_CHECKING, Generic, Any, TypeVar
if TYPE_CHECKING:
T = TypeVar('T')
class PatchDict(dict[Any, Any], Generic[T]):
pass |
Hi @vitalik. Thanks for coming back. I tried your suggested solution. here is the full snippet and the error
Error ![]()
Notice the later error comes because i try to do |
I think the issue is that you annotate the PatchDict as a dictionary. I tried this and works with pyright.
It does look incomplete to me though or not the proper way to type this descriptor. Ideally the PatchDictUtil class should be typed such that the custom If I find something more precise I will let you know. Let me know if you know how this typing can be achieved in a more complete way. Note: This may only work on python 3.12 as generics types where introduced then. |
@vitalik I just realised your snippet above is equivalent to my snippet provided above and backwards compatible to older versions. The issue mentioned by the other guys is because the type definition is declared twice both inside the library and then they try to overwrite it. I edited the library internally and it works like a charm. Could we merge your fix and make a release? |
@nikatlas @sxoinas12 @khurramshahzad456 - can you check against this branch ? https://github.com/vitalik/django-ninja/tree/1441-patch-dict-type-check |
I tested it with
|
Fixed with this one Thank you |
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
when using
PatchDict
I do get the belowerror
when I perform my type checking:Example:
i have the below schema
when using it in my view with
PatchDict
as described in your documentation I do get the above type error, which i believe it's expected since you already it have it as an annotated type hereIs there a mistake in your documentation ? I would expect this to do what it describes and make my fields optional.
Versions:
3.13.0
5.1.5
1.4.1
2.11.3
The text was updated successfully, but these errors were encountered: