Skip to content

Pyright flaging mixed keys dictionary as an error #9187

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

You must be logged in to vote

This is a legitimate type violation, so pyright is correct to generate an error here. You can suppress type errors with a # type: ignore or # pyright: ignore comments, but it's better to fix your code to eliminate the type violation. Otherwise you defeat the purpose of a type checker.

If your intent is for results to be a dict that accepts values of any type, you can declare its type as dict[str, object] by providing a type annotation.

results: dict[str, object] = ...

For more information about type declarations and type inference, refer to the pyright documentation.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Pilgrim1379
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