PY-59241 Restore compatibility of PyTypeCheckerExtension with the "dev.ngocta.pycharm-odoo" plugin

However, the plugin is seemingly modifying type parameter substitutions in this extension, which
is discouraged and won't work from now on. We should contact its author about it.

GitOrigin-RevId: 3438afa86f6330386c52f58f5a98d1271c05e006
This commit is contained in:
Mikhail Golubev
2024-02-20 14:27:37 +02:00
committed by intellij-monorepo-bot
parent 0dab11a1a3
commit 8ebcb1ec88
2 changed files with 17 additions and 3 deletions

View File

@@ -110,7 +110,7 @@ public final class PyTypeChecker {
}
for (PyTypeCheckerExtension extension : PyTypeCheckerExtension.EP_NAME.getExtensionList()) {
final Optional<Boolean> result = extension.match(expected, actual, context.context, context.mySubstitutions.typeVars);
final Optional<Boolean> result = extension.match(expected, actual, context.context, context.mySubstitutions);
if (result.isPresent()) {
return result;
}

View File

@@ -2,6 +2,7 @@
package com.jetbrains.python.psi.types;
import com.intellij.openapi.extensions.ExtensionPointName;
import one.util.streamex.EntryStream;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -17,14 +18,27 @@ public interface PyTypeCheckerExtension {
ExtensionPointName<PyTypeCheckerExtension> EP_NAME = ExtensionPointName.create("Pythonid.typeCheckerExtension");
@NotNull
default Optional<Boolean> match(@Nullable PyType expected,
@Nullable PyType actual,
@NotNull TypeEvalContext context,
@NotNull PyTypeChecker.GenericSubstitutions substitutions) {
Map<PyGenericType, PyType> legacyTypeVarSubs = EntryStream.of(substitutions.getTypeVars())
.selectKeys(PyGenericType.class)
.toMap();
return match(expected, actual, context, legacyTypeVarSubs);
}
/**
* Behaviour the same as {@link PyTypeChecker#match(PyType, PyType, TypeEvalContext, Map)}
*
* @see PyTypeChecker#match(PyType, PyType, TypeEvalContext, Map)
* @deprecated use {@link #match(PyType, PyType, TypeEvalContext, PyTypeChecker.GenericSubstitutions)}
*/
@Deprecated(forRemoval = true)
@NotNull
Optional<Boolean> match(@Nullable PyType expected,
@Nullable PyType actual,
@NotNull TypeEvalContext context,
@NotNull Map<? extends PyTypeParameterType, PyType> substitutions);
@NotNull Map<PyGenericType, PyType> substitutions);
}