-
Notifications
You must be signed in to change notification settings - Fork 771
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
reportTypedDictNotRequiredAccess seems not works correctly. #1926
Comments
To see logs, you should:
|
The type Pyright (the type checker that underlies pylance) will "narrow" the type and (internally mark the corresponding key as no longer "not-required") based on conditional checks, like this: if "key1" in my_dict:
print(my_dict["key1"]) Note that you don't need to fetch the Pyright doesn't currently narrow the TypedDict type on assignment. I think that's a good enhancement request. I've created a tracking feature request in the pyright repo. In the meantime, you can use the pattern above. Another solution is to enclose the usage in a try block. Or you can suppress the # pyright: reportTypedDictNotRequiredAccess=false Or you can disable that diagnostic rule throughout your entire project using pylance settings to set the diagnostic severity to "none". |
I've added support for TypedDict narrowing on assignment. This support will be in the next release of pylance. |
This issue has been fixed in version 2021.10.1, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#2021101-14-october-2021 |
Environment data
PyLance : v2021.10.1-pre.1
Expected behaviour
PyLance should know that we defined the key when creating the object, and nowhere after declaration we deleted any key.
Also, even if we add a check if the key exist there is an avert.
Actual behaviour
PyLance trigger the reportTypedDictNotRequiredAccess error even if it should not.
Logs
Code Snippet / Additional information
The text was updated successfully, but these errors were encountered: