From 04f49fbbc454062795f2679bab7f1bc455099fd2 Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Tue, 28 Feb 2017 16:51:29 +0300 Subject: [PATCH] PY-20057 Treat the second argument of isinstance() as instance type, not class type --- .../codeInsight/controlflow/PyTypeAssertionEvaluator.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/python/src/com/jetbrains/python/codeInsight/controlflow/PyTypeAssertionEvaluator.java b/python/src/com/jetbrains/python/codeInsight/controlflow/PyTypeAssertionEvaluator.java index a6c983c6b5ab..377d5b4520b3 100644 --- a/python/src/com/jetbrains/python/codeInsight/controlflow/PyTypeAssertionEvaluator.java +++ b/python/src/com/jetbrains/python/codeInsight/controlflow/PyTypeAssertionEvaluator.java @@ -68,7 +68,11 @@ public class PyTypeAssertionEvaluator extends PyRecursiveElementVisitor { final PyReferenceExpression target = (PyReferenceExpression)args[0]; final PyExpression typeElement = args[1]; - pushAssertion(target, myPositive, context -> context.getType(typeElement)); + // TODO support tuple of types as the second argument of isinstance() + pushAssertion(target, myPositive, context -> { + final PyType type = context.getType(typeElement); + return type instanceof PyClassType ? ((PyClassType)type).toInstance() : type; + }); } } else if (node.isCalleeText(PyNames.CALLABLE_BUILTIN)) { @@ -183,7 +187,7 @@ public class PyTypeAssertionEvaluator extends PyRecursiveElementVisitor { final PyType initial = context.getType(target); final PyType suggested = suggestedType.apply(context); - if (!PyUnionType.class.isInstance(initial) && + if (!(initial instanceof PyUnionType) && !PyTypeChecker.isUnknown(initial) && PyTypeChecker.match(suggested, initial, context)) { return initial;