diff --git a/python/python-psi-impl/resources/messages/PyPsiBundle.properties b/python/python-psi-impl/resources/messages/PyPsiBundle.properties
index 1a88b2624a05..1e09a306744f 100644
--- a/python/python-psi-impl/resources/messages/PyPsiBundle.properties
+++ b/python/python-psi-impl/resources/messages/PyPsiBundle.properties
@@ -1100,6 +1100,7 @@ INSP.typeddict.required.and.not.required.cannot.be.nested=Required[] and NotRequ
INSP.typeddict.read.only.cannot.be.nested=ReadOnly[] cannot be nested
INSP.typeddict.required.notrequired.must.have.exactly.one.type.argument=''{0}'' must have exactly one type argument
INSP.typeddict.unexpected.argument.for.__init_subclass__.of.TypedDict=Unexpected argument ''{0}'' for __init_subclass__ of TypedDict
+INSP.typeddict.expected.a.dictionary.literal=Expected dictionary literal
# PyTypeHintsInspection
INSP.NAME.type.hints=Invalid type hints definitions and usages
diff --git a/python/python-psi-impl/src/com/jetbrains/python/inspections/PyTypedDictInspection.kt b/python/python-psi-impl/src/com/jetbrains/python/inspections/PyTypedDictInspection.kt
index a59025f1695b..1f4dcb13875d 100644
--- a/python/python-psi-impl/src/com/jetbrains/python/inspections/PyTypedDictInspection.kt
+++ b/python/python-psi-impl/src/com/jetbrains/python/inspections/PyTypedDictInspection.kt
@@ -92,8 +92,10 @@ class PyTypedDictInspection : PyInspection() {
if (callExpression != null) {
val callee = callExpression.callee
if (callee != null && PyTypedDictTypeProvider.isTypedDict(callee, myTypeEvalContext)) {
- val fields = PyPsiUtils.flattenParens(callExpression.arguments.getOrNull(1))
+ val argument1 = callExpression.arguments.getOrNull(1)
+ val fields = PyPsiUtils.flattenParens(argument1)
if (fields !is PyDictLiteralExpression) {
+ registerProblem(argument1, PyPsiBundle.message("INSP.typeddict.expected.a.dictionary.literal"))
return
}
diff --git a/python/testSrc/com/jetbrains/python/inspections/PyTypedDictInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyTypedDictInspectionTest.java
index cea057c631c6..0c5737718a75 100644
--- a/python/testSrc/com/jetbrains/python/inspections/PyTypedDictInspectionTest.java
+++ b/python/testSrc/com/jetbrains/python/inspections/PyTypedDictInspectionTest.java
@@ -196,8 +196,13 @@ public class PyTypedDictInspectionTest extends PyInspectionTestCase {
}
public void testIncorrectTypedDictArguments() {
- doTestByText("from typing import TypedDict\n" +
- "c = TypedDict(\"c\", [1, 2, 3])");
+ doTestByText("""
+ from typing import TypedDict
+ BadTD1 = TypedDict("BadTD1", [1, 2, 3])
+
+ fields = {"v": int}
+ BadTD2 = TypedDict("BadTD2", fields)
+ """);
}
public void testTypedDictNonStringKey() {