Wrong type warning when working with dictionary


Consider this very simple python example:

def b():
:rtype: dict[str, int]
return {"b": 1}

a = b()

a["test"] = "test"



The last line gives me this error

Expected type 'int' (matched generic type '_VT'), got 'str' instead

which is not correct in my opinion. Is there any workaround for this. I don't like to specify ` :rtype: dict[str, int | str]` in function because it is incorrect. 


I use

PyCharm 2018.3.3 (Professional Edition)
Build #PY-183.5153.39, built on January 9, 2019
JRE: 1.8.0_152-release-1343-b26 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.15.0-43-generic


1 comment


It seems to be known issue https://youtrack.jetbrains.com/issue/PY-33201, please vote for it and follow for updates.


Please sign in to leave a comment.