Commit 2977985a authored by Mikhail Golubev's avatar Mikhail Golubev Committed by intellij-monorepo-bot
Browse files

PY-59791 Simplify extracting a wrapped type from sqlalchemy.orm.Mapped

Use PyTypingTypeProvider.getAnnotationValue for that, similarly to already
re-used in other places PyTypingTypeProvider.getReturnTypeAnnotation.

Also, I've better separated handling of attributes explicitly annotated with Mapped
and just initialized with a mapped_column call. It will help to remove special
casing for Mapped once generic descriptors are fully supported in type inference
(PY-26184).

(cherry picked from commit eaeb66abd26b851507970b112360631704b41db3)

GitOrigin-RevId: 442369f52ed5c6b97d91648f7968ff3a7ba285cb
parent 79a9f5b7
Showing with 5 additions and 4 deletions
+5 -4
......@@ -38,6 +38,7 @@ import com.jetbrains.python.psi.resolve.RatedResolveResult;
import com.jetbrains.python.psi.types.*;
import com.jetbrains.python.psi.types.PyTypeParameterMapping.Option;
import one.util.streamex.StreamEx;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
......@@ -345,8 +346,8 @@ public final class PyTypingTypeProvider extends PyTypeProviderWithCustomContext<
return null;
}
@Nullable
public static PyExpression getReturnTypeAnnotation(@NotNull PyFunction function, TypeEvalContext context) {
@ApiStatus.Internal
public static @Nullable PyExpression getReturnTypeAnnotation(@NotNull PyFunction function, TypeEvalContext context) {
final PyExpression returnAnnotation = getAnnotationValue(function, context);
if (returnAnnotation != null) {
return returnAnnotation;
......@@ -1207,8 +1208,8 @@ public final class PyTypingTypeProvider extends PyTypeProviderWithCustomContext<
return ContainerUtil.exists(names, qualifiedNames::contains);
}
@Nullable
private static PyExpression getAnnotationValue(@NotNull PyAnnotationOwner owner, @NotNull TypeEvalContext context) {
@ApiStatus.Internal
public static @Nullable PyExpression getAnnotationValue(@NotNull PyAnnotationOwner owner, @NotNull TypeEvalContext context) {
if (context.maySwitchToAST(owner)) {
final PyAnnotation annotation = owner.getAnnotation();
if (annotation != null) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment