mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Infer type for targets initialized through TypeVar(...) (PY-28227)
This commit is contained in:
@@ -491,6 +491,14 @@ public class PyTypingTypeProvider extends PyTypeProviderBase {
|
||||
return annotatedType;
|
||||
}
|
||||
|
||||
final PyExpression assignedValue = PyTypingAliasStubType.getAssignedValueStubLike(target);
|
||||
if (assignedValue != null) {
|
||||
final PyType type = getGenericTypeFromTypeVar(assignedValue, new Context(context));
|
||||
if (type != null) {
|
||||
return Ref.create(type);
|
||||
}
|
||||
}
|
||||
|
||||
final String name = target.getReferencedName();
|
||||
final ScopeOwner scopeOwner = ScopeUtil.getScopeOwner(target);
|
||||
if (name == null || scopeOwner == null) {
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
from typing import TypeVar
|
||||
|
||||
T = TypeVar('T')
|
||||
@@ -3230,6 +3230,20 @@ public class PyTypeTest extends PyTestCase {
|
||||
doTest("float", "expr = round(True, 1)");
|
||||
}
|
||||
|
||||
// PY-28227
|
||||
public void testTypeVarTargetAST() {
|
||||
doTest("T",
|
||||
"from typing import TypeVar\n" +
|
||||
"expr = TypeVar('T')");
|
||||
}
|
||||
|
||||
// PY-28227
|
||||
public void testTypeVarTargetStub() {
|
||||
doMultiFileTest("T",
|
||||
"from a import T\n" +
|
||||
"expr = T");
|
||||
}
|
||||
|
||||
private static List<TypeEvalContext> getTypeEvalContexts(@NotNull PyExpression element) {
|
||||
return ImmutableList.of(TypeEvalContext.codeAnalysis(element.getProject(), element.getContainingFile()).withTracing(),
|
||||
TypeEvalContext.userInitiated(element.getProject(), element.getContainingFile()).withTracing());
|
||||
|
||||
Reference in New Issue
Block a user