PY-20710 Support 'Generator' typing class

Check YieldType of yield expressions in PyTypeCheckerInspection
Check that (Async)Generator is used in (async) function
Check that in 'yield from' sync Generator is used
Convert PyMakeFunctionReturnTypeQuickFix into PsiUpdateModCommandAction
Infer Generator type for lambdas
When getting function type from annotation, do not convert Generator to AsyncGenerator
Introduce GeneratorTypeDescriptor to simplify working with generator annotations


Merge-request: IJ-MR-146521
Merged-by: Aleksandr Govenko <aleksandr.govenko@jetbrains.com>

(cherry picked from commit b3b8182168c5224f0e03f54d443171ccf6ca7b89)

IJ-MR-146521

GitOrigin-RevId: a95670d7e2787015bcf162637ea6d7bfb47a312a
This commit is contained in:
Aleksandr.Govenko
2024-12-04 15:22:15 +00:00
committed by intellij-monorepo-bot
parent 362a0344a7
commit 70fe60b4c8
22 changed files with 509 additions and 122 deletions

View File

@@ -1,6 +1,7 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.psi;
import com.intellij.openapi.util.Pair;
import com.intellij.psi.PsiNameIdentifierOwner;
import com.intellij.psi.StubBasedPsiElement;
import com.intellij.util.ArrayFactory;

View File

@@ -2,6 +2,9 @@
package com.jetbrains.python.psi;
import com.jetbrains.python.ast.PyAstYieldExpression;
import com.jetbrains.python.psi.types.PyType;
import com.jetbrains.python.psi.types.TypeEvalContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -11,4 +14,17 @@ public interface PyYieldExpression extends PyAstYieldExpression, PyExpression {
default PyExpression getExpression() {
return (PyExpression)PyAstYieldExpression.super.getExpression();
}
/**
* @return For {@code yield}, returns type of its expression. For {@code yield from} - YieldType of the delegate
*/
@Nullable
PyType getYieldType(@NotNull TypeEvalContext context);
/**
* @return If containing function is annotated with Generator (or AsyncGenerator), returns SendType from annotation.
* Otherwise, Any for {@code yield} and SendType of the delegate for {@code yield from}
*/
@Nullable
PyType getSendType(@NotNull TypeEvalContext context);
}