PY-78653 Fix constrained type variable substitution

Subtypes of types constrained by a type variable should be treated as their respective explicitly listed base types in the context of the type variable.

GitOrigin-RevId: ecaac1614f66974b6e6c2217ac0a90321d049f76
This commit is contained in:
Petr
2025-01-23 12:27:53 +01:00
committed by intellij-monorepo-bot
parent 28a490867b
commit af57462aa7
11 changed files with 155 additions and 74 deletions

View File

@@ -1,8 +1,11 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.psi.types;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
/**
* Represents a type parameter that should be substituted with a single type during the unification process.
* Normally, it's declared using {@code TypeVar} function from the "typing" module, as in
@@ -14,6 +17,8 @@ import org.jetbrains.annotations.Nullable;
* but can also come from other sources, such as docstrings.
*/
public interface PyTypeVarType extends PyTypeParameterType, PyInstantiableType<PyTypeVarType> {
@NotNull List<@Nullable PyType> getConstraints();
/**
* Returns the upper bound for this type parameter if it was specified.
* <p>