mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
PY-21048 Fixed: Strange inspection in return values of async function
Unwrap __coroutine in PyTypeCheckerInspection when matching expected and actual return types
This commit is contained in:
@@ -91,7 +91,7 @@ public class PyTypeCheckerInspection extends PyInspection {
|
||||
if (annotation != null || typeCommentAnnotation != null) {
|
||||
final PyExpression returnExpr = node.getExpression();
|
||||
final PyType actual = returnExpr != null ? myTypeEvalContext.getType(returnExpr) : PyNoneType.INSTANCE;
|
||||
final PyType expected = myTypeEvalContext.getReturnType(function);
|
||||
final PyType expected = getExpectedReturnType(function);
|
||||
if (!PyTypeChecker.match(expected, actual, myTypeEvalContext)) {
|
||||
final String expectedName = PythonDocumentationProvider.getTypeName(expected, myTypeEvalContext);
|
||||
final String actualName = PythonDocumentationProvider.getTypeName(actual, myTypeEvalContext);
|
||||
@@ -105,6 +105,17 @@ public class PyTypeCheckerInspection extends PyInspection {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PyType getExpectedReturnType(@NotNull PyFunction function) {
|
||||
final PyType returnType = myTypeEvalContext.getReturnType(function);
|
||||
|
||||
if (returnType instanceof PyCollectionType && PyNames.FAKE_COROUTINE.equals(returnType.getName())) {
|
||||
return ((PyCollectionType)returnType).getElementTypes(myTypeEvalContext).get(0);
|
||||
}
|
||||
|
||||
return returnType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyFunction(PyFunction node) {
|
||||
final PyAnnotation annotation = node.getAnnotation();
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
async def test(self, a) -> int:
|
||||
return 123
|
||||
@@ -158,4 +158,9 @@ public class Py3TypeCheckerInspectionTest extends PyTestCase {
|
||||
public void testComprehensionsOverAsyncGenerator() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-21048
|
||||
public void testAsyncFunctionReturnType() {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user