PY-78475: Added code completion for PEP 695 type aliases

GitOrigin-RevId: a1212179c22b9cfd2b2481abe7b6dd03463c3b6a
This commit is contained in:
Alex Grönholm
2025-01-23 16:16:09 +00:00
committed by intellij-monorepo-bot
parent 15956de4f7
commit 97deb166a7
7 changed files with 17 additions and 2 deletions
@@ -205,7 +205,11 @@ public final class PyClassNameCompletionContributor extends PyImportableNameComp
@NotNull TypeEvalContext context) {
if (PyTypingTypeProvider.isInsideTypeHint(position, context)) {
// Not all names from typing.py are defined as classes
return definition instanceof PyClass || ArrayUtil.contains(fqn.getFirstComponent(), "typing", "typing_extensions");
return (
definition instanceof PyClass ||
definition instanceof PyTypeAliasStatement ||
ArrayUtil.contains(fqn.getFirstComponent(), "typing", "typing_extensions")
);
}
if (PsiTreeUtil.getParentOfType(position, PyPattern.class, false) != null) {
return definition instanceof PyClass;
@@ -60,7 +60,7 @@ public class PyFileElementType extends IStubFileElementType<PyFileStub> {
@Override
public int getStubVersion() {
// Don't forget to update versions of indexes that use the updated stub-based elements
return 96;
return 97;
}
@Override
@@ -42,6 +42,7 @@ public class PyTypeAliasStatementElementType extends PyStubElementType<PyTypeAli
String name = stub.getName();
if (name != null && PyUtil.getInitialUnderscores(name) == 0 && stub.getParentStub() instanceof PyFileStub) {
sink.occurrence(PyTypeAliasNameIndex.KEY, name);
sink.occurrence(PyExportedModuleAttributeIndex.KEY, name);
}
}
@@ -0,0 +1 @@
type ExampleType = int | str
@@ -0,0 +1,3 @@
from lib import ExampleType
xs: ExampleType
@@ -0,0 +1 @@
xs: ExampleTy<caret>
@@ -83,6 +83,11 @@ public class PyClassNameCompletionTest extends PyTestCase {
doTest();
}
// PY-78475
public void testTypeAlias() {
doTest();
}
// PY-22422
public void testReformatUpdatedFromImport() {
getPythonCodeStyleSettings().FROM_IMPORT_WRAPPING = CommonCodeStyleSettings.WRAP_ALWAYS;