From 1fdb8235e9664abe2c0e6e631d319a20040534d9 Mon Sep 17 00:00:00 2001 From: KotlinIsland Date: Tue, 13 Oct 2020 17:45:32 +0300 Subject: [PATCH] PY-44714 PyTypedDictInspection: don't register problem with None Fix false positive with None as TypedDict value type close #1452 GitOrigin-RevId: 7c02d8928f2e9ef3612aaf69d6daeb5a1b71cb95 --- .../python/inspections/PyTypedDictInspection.kt | 2 +- .../python/inspections/PyTypedDictInspectionTest.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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 137ea5edd7bf..437d1f1aedda 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 @@ -278,7 +278,7 @@ class PyTypedDictInspection : PyInspection() { * Checks that [expression] with [strType] name is a type */ private fun checkValueIsAType(expression: PyExpression?, strType: String?) { - if (expression !is PyReferenceExpression && expression !is PySubscriptionExpression || strType == null) { + if (expression !is PyReferenceExpression && expression !is PySubscriptionExpression && expression !is PyNoneLiteralExpression || strType == null) { registerProblem(expression, PyPsiBundle.message("INSP.typeddict.value.must.be.type"), ProblemHighlightType.WEAK_WARNING) return } diff --git a/python/testSrc/com/jetbrains/python/inspections/PyTypedDictInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyTypedDictInspectionTest.java index 7c7e54f975d4..af680452e795 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyTypedDictInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyTypedDictInspectionTest.java @@ -300,6 +300,16 @@ public class PyTypedDictInspectionTest extends PyInspectionTestCase { " return movie[key]")); } + // PY-44714 + public void testNoneAsType() { + runWithLanguageLevel( + LanguageLevel.getLatest(), + () -> doTestByText("from typing import TypedDict\n" + + "class X(TypedDict):\n" + + " n: None\n" + + "Y = TypedDict('Y', {'n': None})\n")); + } + @NotNull @Override protected Class getInspectionClass() {