Problem description
Argument of type "list[int]" cannot be assigned to parameter "__value" of type "int" in function "__setitem__"
"list[int]" is incompatible with "int"
Expected behavior
It expected to be running without the debug reminder since it works properly, because sometimes it leads misunderstanding
Actual behavior
It should runs without debug reminder
Steps to reproduce
May be it is a typo error or need complier to be refacted
Browser
Chrome
OS
Windows11
Device if mobile
N/A
Plan
free tier
#This is the original Code, and the line after "Corrected assignment for key 'c' as a list" all shows red line under the text with debug notice
dict = {
"a" : 1,
"b" : 2,
"c" : 3,
}
# Corrected assignment for key 'c' as a list
dict['c'] = [1, 2, 3]
dict[1] = 4
print(dict[1])
Could you try calling the object something other than dict
? Even if that doesn’t fix your issue, it’s better practice. (dict
is a builtin, and you’re overwriting it)
2 Likes
Hello, you should indeed rename your dictionary to a name other than dict
. This alone is not the issue though.
When you first created the variable, you used only str
keys and only int
values. So, the typechecker assumed that would always be the case (assumed the type of your variable). Typechecking is mostly for code quality and does not affect running the program at all.
To disable typechecking in your repl, open pyproject.toml
and insert this underneath the [tool.pyright]
section:
typeCheckingMode = "off"
(changes take a few seconds to apply)
Note that other warnings such as syntax warnings will still appear.
1 Like