PY-76812 Conformance test failure: typeddicts_alt_syntax.py

TypedDict() second argument has to be a dictionary literal

GitOrigin-RevId: 98dd2a2d8cf1d89bc9513e1562fc751d13812ca4
This commit is contained in:
Petr
2024-12-19 18:50:44 +00:00
committed by intellij-monorepo-bot
parent 49b3258737
commit 72dee29a9c
3 changed files with 11 additions and 3 deletions
@@ -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
@@ -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
}
@@ -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", <warning descr="Expected dictionary literal">[1, 2, 3]</warning>)
fields = {"v": int}
BadTD2 = TypedDict("BadTD2", <warning descr="Expected dictionary literal">fields</warning>)
""");
}
public void testTypedDictNonStringKey() {