mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Don't show non-public names from buitlins stub in completion (PY-22828)
The Typeshed stub from buitlins contains several non-public names: * Imports from other modules * Protected names (_foo)
This commit is contained in:
@@ -637,7 +637,19 @@ public class PyReferenceImpl implements PsiReferenceEx, PsiPolyVariantReference
|
||||
|
||||
// include our own names
|
||||
final int underscores = PyUtil.getInitialUnderscores(element.getName());
|
||||
final CompletionVariantsProcessor processor = new CompletionVariantsProcessor(element);
|
||||
final PyBuiltinCache builtinCache = PyBuiltinCache.getInstance(element);
|
||||
final CompletionVariantsProcessor processor = new CompletionVariantsProcessor(element, e -> {
|
||||
if (builtinCache.isBuiltin(e)) {
|
||||
final String name = e instanceof PyElement ? ((PyElement)e).getName() : null;
|
||||
if (e instanceof PyImportElement) {
|
||||
return false;
|
||||
}
|
||||
if (name != null && PyUtil.getInitialUnderscores(name) == 1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}, null);
|
||||
final ScopeOwner owner = realContext instanceof ScopeOwner ? (ScopeOwner)realContext : ScopeUtil.getScopeOwner(realContext);
|
||||
if (owner != null) {
|
||||
PyResolveUtil.scopeCrawlUp(processor, owner, null, null);
|
||||
@@ -648,7 +660,7 @@ public class PyReferenceImpl implements PsiReferenceEx, PsiPolyVariantReference
|
||||
KeywordArgumentCompletionUtil.collectFunctionArgNames(element, ret, TypeEvalContext.codeCompletion(element.getProject(), element.getContainingFile()));
|
||||
|
||||
// include builtin names
|
||||
final PyFile builtinsFile = PyBuiltinCache.getInstance(element).getBuiltinsFile();
|
||||
final PyFile builtinsFile = builtinCache.getBuiltinsFile();
|
||||
if (builtinsFile != null) {
|
||||
PyResolveUtil.scopeCrawlUp(processor, builtinsFile, null, null);
|
||||
}
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ public class PythonBuiltinReferenceResolveProvider implements PyReferenceResolve
|
||||
|
||||
// ...as a builtin symbol
|
||||
final PyFile builtinsFile = builtinCache.getBuiltinsFile();
|
||||
if (builtinsFile != null && !PyUtil.isClassPrivateName(referencedName)) {
|
||||
if (builtinsFile != null && !PyUtil.isClassPrivateName(referencedName) && PyUtil.getInitialUnderscores(referencedName) != 1) {
|
||||
for (RatedResolveResult resolveResult : builtinsFile.multiResolveName(referencedName)) {
|
||||
result.add(new ImportedResolveResult(resolveResult.getElement(), resolveResult.getRate(), null));
|
||||
}
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
print(<error descr="Unresolved reference '_T'">_T</error>, <error descr="Unresolved reference '_KT'">_KT</error>)
|
||||
print(__import__)
|
||||
print(len)
|
||||
@@ -1114,6 +1114,22 @@ public class PythonCompletionTest extends PyTestCase {
|
||||
assertSameElements(variants, "mod1", "mod2", "foo", "_bar");
|
||||
}
|
||||
|
||||
// PY-22828
|
||||
public void testNoImportedBuiltinNames() {
|
||||
final List<String> suggested = doTestByText("T<caret>\n");
|
||||
assertNotNull(suggested);
|
||||
assertContainsElements(suggested, "TypeError");
|
||||
assertDoesntContain(suggested, "TypeVar");
|
||||
}
|
||||
|
||||
// PY-22828
|
||||
public void testNoProtectedBuiltinNames() {
|
||||
final List<String> suggested = doTestByText("_<caret>\n");
|
||||
assertNotNull(suggested);
|
||||
assertContainsElements(suggested, "__import__");
|
||||
assertDoesntContain(suggested, "_T", "_KT");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return super.getTestDataPath() + "/completion";
|
||||
|
||||
+5
@@ -763,6 +763,11 @@ public class PyUnresolvedReferencesInspectionTest extends PyInspectionTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-22828
|
||||
public void testNoProtectedBuiltinNames() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Class<? extends PyInspection> getInspectionClass() {
|
||||
|
||||
Reference in New Issue
Block a user