Closed vladimir-sama closed 2 weeks ago
Could you provide a self-contained, minimal code sample that exhibits the problem? The code sample above references a bunch of symbols that are not defined.
Here's an attempt to create a minimal repro, but this type checks without errors in pyright:
from typing import TypedDict
class Game(TypedDict):
title: str
x: dict[str, Game] = {"test": {"title": "test"}}
game_list[item_id] = {
'title' : item_title,
'description' : item_description,
'command' : shlex.split(item_command),
'image' : image,
'last_played' : 0,
'time_played' : 0,
'time_added' : int(time.time()),
'is_shell' : False
}
Issue is here, defining an element like game_list[string_key] = {All keys in Game}
Edit:
from typing import TypedDict, Dict
class Game(TypedDict):
title:str
description:str
game_list : Dict[str, Game] = {}
game_list['KEY'] = {
'title' : 'GAME TITLE',
'description' : 'GAME DESC'
}
Somehow no error? Maybe adding more types to keys?
from typing import TypedDict, Dict, List
class Game(TypedDict):
title:str
description:str
dates_played:List[int]
game_list : Dict[str, Game] = {}
game_list['KEY'] = {
'title' : 'GAME TITLE',
'description' : 'GAME DESC',
'dates_played' : [1, 2, 3]
}
Argument of type "dict[str, str | list[int]]" cannot be assigned to parameter "value" of type "Game" in function "__setitem__"
I'm not able to repro the problem with the above code sample. Here's the code in pyright playground.
Perhaps you have an outdated version of pyright installed? Or maybe you have some custom configuration options specified?
Found it, item_description
could have been None
in my code.
This needs better errors, thanks for the help!
Argument of type "dict[str, str | list[str] | int | bool | None]" cannot be assigned to parameter "value" of type "Game" in function "__setItem__"
So this worked in VSCode with Pylance, now I am trying to use Zed with Pyright but it doesn't handle TypedDict. That or I'm using it wrong.