diff --git a/python/python-psi-api/src/com/jetbrains/python/psi/types/TypeEvalContext.java b/python/python-psi-api/src/com/jetbrains/python/psi/types/TypeEvalContext.java index 9a3f773dc41a..c26ce825004c 100644 --- a/python/python-psi-api/src/com/jetbrains/python/psi/types/TypeEvalContext.java +++ b/python/python-psi-api/src/com/jetbrains/python/psi/types/TypeEvalContext.java @@ -297,6 +297,10 @@ public sealed class TypeEvalContext { return Registry.is("python.use.separated.libraries.type.cache") && isLibraryElement(element); } + private static boolean isExternalTypeProviderApplicable(PyTypedElement element) { + return element instanceof PyInstantTypeProvider; + } + public @Nullable PyType getType(final @NotNull PyTypedElement element) { if (canDelegateToLibraryContext(element)) { var context = getLibraryContext(element.getProject()); @@ -311,35 +315,33 @@ public sealed class TypeEvalContext { Pair.create(element, this), false, () -> { - var externalTypeProvider = isInsideExternalTypeProviderCall ? null : - ContainerUtil.find(TypeEvalExternalTypeProvider.EP_NAME.getExtensionList(), - provider -> provider.isAvailable(element)); - - if (externalTypeProvider != null) { - try { - isInsideExternalTypeProviderCall = true; - var provided = externalTypeProvider.provideType(element, this); - isInsideExternalTypeProviderCall = false; - if (provided != null) { - var type = provided.get(); - myExternalEvaluated.put(element, type == null ? PyNullType.INSTANCE : type); - return type; + if (!isExternalTypeProviderApplicable(element) && !isInsideExternalTypeProviderCall) { + var externalTypeProvider = + ContainerUtil.find(TypeEvalExternalTypeProvider.EP_NAME.getExtensionList(), TypeEvalExternalTypeProvider::isAvailable); + if (externalTypeProvider != null) { + try { + isInsideExternalTypeProviderCall = true; + var provided = externalTypeProvider.provideType(element, this); + isInsideExternalTypeProviderCall = false; + if (provided != null) { + var type = provided.get(); + myExternalEvaluated.put(element, type == null ? PyNullType.INSTANCE : type); + return type; + } + } + catch (ProcessCanceledException e) { + throw e; + } + catch (Exception e) { + logger.warn("Exception during external type provider " + externalTypeProvider.getClass().getName(), e); } } - catch (ProcessCanceledException e) { - throw e; - } - catch (Exception e) { - logger.warn("Exception during external type provider " + externalTypeProvider.getClass().getName(), e); - } } - else { - PyType type = element.getType(this, Key.INSTANCE); - assertValid(type, element); - myEvaluated.put(element, type == null ? PyNullType.INSTANCE : type); - return type; - } - return null; + + PyType type = element.getType(this, Key.INSTANCE); + assertValid(type, element); + myEvaluated.put(element, type == null ? PyNullType.INSTANCE : type); + return type; } ); } diff --git a/python/python-psi-api/src/com/jetbrains/python/psi/types/TypeEvalExternalTypeProvider.kt b/python/python-psi-api/src/com/jetbrains/python/psi/types/TypeEvalExternalTypeProvider.kt index 9bc44c92feb9..eaec9ddeffb1 100644 --- a/python/python-psi-api/src/com/jetbrains/python/psi/types/TypeEvalExternalTypeProvider.kt +++ b/python/python-psi-api/src/com/jetbrains/python/psi/types/TypeEvalExternalTypeProvider.kt @@ -3,7 +3,6 @@ package com.jetbrains.python.psi.types import com.intellij.openapi.extensions.ExtensionPointName import com.intellij.openapi.util.Ref -import com.intellij.psi.PsiElement import com.jetbrains.python.psi.PyTypedElement import org.jetbrains.annotations.ApiStatus @@ -13,7 +12,7 @@ import org.jetbrains.annotations.ApiStatus */ @ApiStatus.Internal interface TypeEvalExternalTypeProvider { - fun isAvailable(element: PsiElement): Boolean + fun isAvailable(): Boolean fun provideType(element: PyTypedElement, context: TypeEvalContext): Ref?