mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-20057 Treat the second argument of isinstance() as instance type, not class type
This commit is contained in:
+6
-2
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user