mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-61858 PEP 695 Type Parameter Syntax: Add Language injections inside quoted forward references
GitOrigin-RevId: f38d5d5d3ae9529e2ffb8ddd252f399fb6cea7bd
This commit is contained in:
committed by
intellij-monorepo-bot
parent
30a5cc3323
commit
409ee5968e
@@ -63,6 +63,9 @@ public class PyTypingAnnotationInjector extends PyInjectorBase {
|
||||
if (isInsideValueOfExplicitTypeAnnotation(expr)) {
|
||||
return PyTypeHintDialect.INSTANCE;
|
||||
}
|
||||
if (isInsideNewStyleTypeVarBound(context)) {
|
||||
return PyTypeHintDialect.INSTANCE;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -133,6 +136,10 @@ public class PyTypingAnnotationInjector extends PyInjectorBase {
|
||||
return function != null && function.getTypeComment() == comment;
|
||||
}
|
||||
|
||||
private static boolean isInsideNewStyleTypeVarBound(@NotNull PsiElement element) {
|
||||
return PsiTreeUtil.getParentOfType(element, PyTypeParameter.class, true, PyTypeParameterListOwner.class) != null;
|
||||
}
|
||||
|
||||
private static boolean isTypingAnnotation(@NotNull String s) {
|
||||
return RE_TYPING_ANNOTATION.matcher(s).matches();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
class A[T: "MyClass"]: ...
|
||||
<ref>
|
||||
|
||||
class MyClass: ...
|
||||
@@ -0,0 +1,4 @@
|
||||
def foo[T: "MyClass"](x: T) -> T: ...
|
||||
<ref>
|
||||
|
||||
class MyClass: ...
|
||||
@@ -0,0 +1,4 @@
|
||||
type myType[T: "MyClass"] = list[T]
|
||||
<ref>
|
||||
|
||||
class MyClass: ...
|
||||
@@ -74,4 +74,19 @@ public class PyInjectionResolveTest extends PyResolveTestCase {
|
||||
public void testFunctionTypeCommentReturnTypeReference() {
|
||||
assertResolvesTo(PyClass.class, "MyClass");
|
||||
}
|
||||
|
||||
// PY-61858
|
||||
public void testNewStyleGenericClassBoundForwardReference() {
|
||||
assertResolvesTo(PyClass.class, "MyClass");
|
||||
}
|
||||
|
||||
// PY-61858
|
||||
public void testNewStyleGenericFunctionBoundForwardReference() {
|
||||
assertResolvesTo(PyClass.class, "MyClass");
|
||||
}
|
||||
|
||||
// PY-61858
|
||||
public void testNewStyleGenericTypeAliasForwardReference() {
|
||||
assertResolvesTo(PyClass.class, "MyClass");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user