Skip to content

False positive when set item for the dict which has auto deduced type? #8652

Answered by erictraut
scruel asked this question in Q&A
Discussion options

You must be logged in to vote

Pyright is working as designed here, so I don't consider this a bug.

The inferred type of the expression assigned to q is dict[str, dict[str, list[Any]]]. The second line attempts to set a value in this dict object that violates its type, hence the type error.

For details about pyright's default inference behaviors for dict expressions, refer to this documentation.

You can override the default inference behaviors by providing a type declaration for q in this case.

from typing import Any

q: dict[str, Any] = {"bool": {"must": []}}
q["query_parsed"] = False

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by scruel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants