-
Notifications
You must be signed in to change notification settings - Fork 767
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
Incorrect reportOptionalSubscript when accessing List with checked length. #3077
Comments
Deleting the |
I'm not able to repro the problem you're seeing. Can you please verify that the above code snippet is correct? It contains a bug on the second line. Even if I fix that bug, I don't see any errors reported by pylance. |
I have fixed the error in line 2 now, please try again to reproduce. |
To confirm, you're able to see the error with the self-contained minimal code sample above? I don't see any error with this code. Please try pasting this code into its own ".py" file and make sure you can repro the problem there. If you can, we'll need to figure out what's different between your configuration and mine. |
I tried and I am not able to reproduce either. I cannot attach the file, therefore here is the full code 1-1: from typing import Optional, List, Dict, Tuple, Any
group_tags: Optional[List[str]] = ["hello", "\"anotherVal\""]
insert_tags: Dict[str, Optional[str]] = {}
tag_data_tuple: List[Tuple[
Optional[Dict[str, str]],
List[Dict[str, Any]]]] = [
({"hello": "wantedId", "anotherVal": "wantedName"}, [{}])
]
for (tag_dict, data) in tag_data_tuple:
if group_tags and tag_dict:
if "something" in group_tags:
pass
else:
insert_tags["id_value"] = tag_dict[group_tags[0].replace("\"", "")]
if len(group_tags) > 1:
insert_tags["name_value"] = tag_dict[group_tags[1].replace("\"", "")] With this code the bug is reliable reproduced. |
OK, thanks. I'm able to repro the problem with that code sample. This is a core type checker issue, so I've created a tracking bug in the pyright repo. |
Thanks - I am surprised, I though that pyright was integrated into pylance. |
Yes, pyright is integrated into pylance. Or perhaps it would be more accurate to say that pylance is built on top of pyright, at least from an architectural layering perspective. All of the core type analysis logic is in pyright, and pylance builds features on top of that capability. This particular bug is in the pyright logic. |
This bug will be fixed in the next release of pyright and will be picked up by pyright in some future release. |
This issue has been fixed in version 2022.7.42, which we've just released. You can find the changelog here: CHANGELOG.md |
Environment data
Code Snippet
Error on the part
group_tags
(last line, accessing [1])Logs
I will add it if requested.
The text was updated successfully, but these errors were encountered: