mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
PY-54167 Add import statement for class when using completion in
__all__ GitOrigin-RevId: 4e54ad17a5965e80557e822ae6a9d323da428f9f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7e0472a5c7
commit
91bddd1e62
@@ -710,6 +710,13 @@ public abstract class PythonCommonCompletionTest extends PythonCommonTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDunderAllClassReference() { // PY-54167
|
||||
myFixture.copyDirectoryToProject(getTestName(true), "");
|
||||
myFixture.configureByFile("__init__.py");
|
||||
myFixture.complete(CompletionType.BASIC, 2);
|
||||
myFixture.checkResultByFile(getTestName(true) + "/__init__.after.py");
|
||||
}
|
||||
|
||||
public void testDunderAllReferenceImport() { // PY-6306
|
||||
doTest();
|
||||
}
|
||||
|
||||
@@ -279,6 +279,9 @@ public final class PyClassNameCompletionContributor extends PyImportableNameComp
|
||||
@NotNull PsiElement position,
|
||||
@NotNull TypeEvalContext typeEvalContext) {
|
||||
if (position.getParent() instanceof PyStringLiteralExpression) {
|
||||
if (isInsideAllInInitPy(position)) {
|
||||
return getImportingInsertHandler();
|
||||
}
|
||||
return getStringLiteralInsertHandler();
|
||||
}
|
||||
// Some names in typing are defined as functions, this rule needs to have priority
|
||||
@@ -291,6 +294,35 @@ public final class PyClassNameCompletionContributor extends PyImportableNameComp
|
||||
return getImportingInsertHandler();
|
||||
}
|
||||
|
||||
private static boolean isInsideAllInInitPy(@NotNull PsiElement position) {
|
||||
PsiFile originalFile = position.getContainingFile();
|
||||
if (originalFile == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!PyNames.INIT_DOT_PY.equals(originalFile.getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PyAssignmentStatement assignment =
|
||||
PsiTreeUtil.getParentOfType(position, PyAssignmentStatement.class);
|
||||
if (assignment == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PyExpression[] targets = assignment.getTargets();
|
||||
if (targets.length != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PyExpression target = targets[0];
|
||||
if (!(target instanceof PyTargetExpression firstTarget)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return PyNames.ALL.equals(firstTarget.getName());
|
||||
}
|
||||
|
||||
private static class Counters {
|
||||
int scannedNames;
|
||||
int privateNames;
|
||||
|
||||
Reference in New Issue
Block a user