PY-44714 PyTypedDictInspection: don't register problem with None

Fix false positive with None as TypedDict value type
close #1452

GitOrigin-RevId: 7c02d8928f2e9ef3612aaf69d6daeb5a1b71cb95
This commit is contained in:
KotlinIsland
2020-10-20 16:11:42 +00:00
committed by intellij-monorepo-bot
parent a43a6b5ba5
commit 1fdb8235e9
2 changed files with 11 additions and 1 deletions
@@ -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
}
@@ -300,6 +300,16 @@ public class PyTypedDictInspectionTest extends PyInspectionTestCase {
" return movie[<warning descr=\"TypedDict key must be a string literal; expected one of ('name', 'year')\">key</warning>]"));
}
// 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<? extends PyInspection> getInspectionClass() {