mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
PY-23247 Fixed: Shorten inferred type of zip function
Process overloads in PythonDocumentationProvider separately.
This commit is contained in:
@@ -48,6 +48,7 @@ import com.jetbrains.python.psi.resolve.PyResolveContext;
|
||||
import com.jetbrains.python.psi.resolve.QualifiedNameFinder;
|
||||
import com.jetbrains.python.psi.types.PyType;
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext;
|
||||
import com.jetbrains.python.pyi.PyiUtil;
|
||||
import com.jetbrains.python.toolbox.ChainIterable;
|
||||
import one.util.streamex.StreamEx;
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
@@ -156,6 +157,9 @@ public class PythonDocumentationProvider extends AbstractDocumentationProvider i
|
||||
@NotNull Function<String, String> escapedNameMapper,
|
||||
@NotNull Function<String, String> escaper,
|
||||
@NotNull TypeEvalContext context) {
|
||||
final List<PyFunction> overloads = PyiUtil.getOverloads(function, context);
|
||||
if (!overloads.isEmpty()) return describeOverload(function, overloads, escapedNameMapper, escaper, context);
|
||||
|
||||
final ChainIterable<String> result = new ChainIterable<>();
|
||||
final String name = function.getName();
|
||||
|
||||
@@ -172,6 +176,33 @@ public class PythonDocumentationProvider extends AbstractDocumentationProvider i
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ChainIterable<String> describeOverload(@NotNull PyFunction function,
|
||||
@NotNull List<PyFunction> overloads,
|
||||
@NotNull Function<String, String> escapedNameMapper,
|
||||
@NotNull Function<String, String> escaper,
|
||||
@NotNull TypeEvalContext context) {
|
||||
final ChainIterable<String> result = new ChainIterable<>();
|
||||
final String name = function.getName();
|
||||
|
||||
result
|
||||
.addItem(escaper.apply("def "))
|
||||
.addItem(escapedNameMapper.apply(escaper.apply(name)))
|
||||
.addItem(escaper.apply("\nPossible types:\n"));
|
||||
|
||||
boolean first = true;
|
||||
for (PyFunction overload : overloads) {
|
||||
if (!first) {
|
||||
result.addItem(escaper.apply("\n"));
|
||||
}
|
||||
result.addItem(escaper.apply("\u2022 "));
|
||||
describeTypeWithLinks(context.getType(overload), context, function, result);
|
||||
first = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String describeExpression(@NotNull PyExpression expression,
|
||||
@NotNull PsiElement originalElement,
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<html><body><code>def <b>foo</b><br>Possible types:<br>• (param: <a href="psi_element://#typename#str">str</a>) -> <a href="psi_element://#typename#str">str</a><br>• (param: <a href="psi_element://#typename#int">int</a>) -> <a href="psi_element://#typename#int">int</a></code></body></html>
|
||||
@@ -0,0 +1,15 @@
|
||||
from typing import overload
|
||||
|
||||
|
||||
@overload
|
||||
def foo(param: str) -> str:
|
||||
pass
|
||||
|
||||
|
||||
@overload
|
||||
def foo(param: int) -> int:
|
||||
pass
|
||||
|
||||
|
||||
def fo<the_ref>o(param: bool) -> bool:
|
||||
pass
|
||||
@@ -0,0 +1,5 @@
|
||||
@typing.overload
|
||||
def foo
|
||||
Possible types:
|
||||
• (p: <a href="psi_element://#typename#int">int</a>) -> <a href="psi_element://#typename#int">int</a>
|
||||
• (p: <a href="psi_element://#typename#str">str</a>) -> <a href="psi_element://#typename#str">str</a>
|
||||
@@ -0,0 +1,14 @@
|
||||
import typing
|
||||
|
||||
|
||||
@typing.overload
|
||||
def foo(p: int) -> int:
|
||||
pass
|
||||
|
||||
|
||||
@typing.overload
|
||||
def foo(p: str) -> str:
|
||||
pass
|
||||
|
||||
|
||||
<the_ref>foo(1)
|
||||
@@ -0,0 +1,4 @@
|
||||
def foo
|
||||
Possible types:
|
||||
• (param: <a href="psi_element://#typename#str">str</a>) -> <a href="psi_element://#typename#str">str</a>
|
||||
• (param: <a href="psi_element://#typename#int">int</a>) -> <a href="psi_element://#typename#int">int</a>
|
||||
@@ -0,0 +1,18 @@
|
||||
from typing import overload
|
||||
|
||||
|
||||
@overload
|
||||
def foo(param: str) -> str:
|
||||
pass
|
||||
|
||||
|
||||
@overload
|
||||
def foo(param: int) -> int:
|
||||
pass
|
||||
|
||||
|
||||
def foo(param: bool) -> bool:
|
||||
pass
|
||||
|
||||
|
||||
<the_ref>foo(1)
|
||||
@@ -0,0 +1 @@
|
||||
<html><body><code>@<i>typing.overload</i><br>def <b>foo</b><br>Possible types:<br>• (p: <a href="psi_element://#typename#int">int</a>) -> <a href="psi_element://#typename#int">int</a><br>• (p: <a href="psi_element://#typename#str">str</a>) -> <a href="psi_element://#typename#str">str</a></code></body></html>
|
||||
@@ -0,0 +1,14 @@
|
||||
import typing
|
||||
|
||||
|
||||
@typing.overload
|
||||
def foo(p: int) -> int:
|
||||
pass
|
||||
|
||||
|
||||
@typing.overload
|
||||
def foo(p: str) -> str:
|
||||
pass
|
||||
|
||||
|
||||
<the_ref>foo(1)
|
||||
@@ -0,0 +1 @@
|
||||
<html><body><code>def <b>foo</b><br>Possible types:<br>• (param: <a href="psi_element://#typename#str">str</a>) -> <a href="psi_element://#typename#str">str</a><br>• (param: <a href="psi_element://#typename#int">int</a>) -> <a href="psi_element://#typename#int">int</a></code></body></html>
|
||||
@@ -0,0 +1,18 @@
|
||||
from typing import overload
|
||||
|
||||
|
||||
@overload
|
||||
def foo(param: str) -> str:
|
||||
pass
|
||||
|
||||
|
||||
@overload
|
||||
def foo(param: int) -> int:
|
||||
pass
|
||||
|
||||
|
||||
def foo(param: bool) -> bool:
|
||||
pass
|
||||
|
||||
|
||||
<the_ref>foo(1)
|
||||
@@ -351,4 +351,35 @@ public class PyQuickDocTest extends LightMarkedTestCase {
|
||||
public void testHoverOverClassWithAllKindSuperClassExpressions() {
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON30, this::checkHover);
|
||||
}
|
||||
|
||||
// PY-23247
|
||||
public void testOverloads() {
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON35, this::checkHTMLOnly);
|
||||
}
|
||||
|
||||
// PY-23247
|
||||
public void testHoverOverOverloads() {
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON35, this::checkHover);
|
||||
}
|
||||
|
||||
// PY-23247
|
||||
public void testOverloadsAndImplementation() {
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON35, this::checkHTMLOnly);
|
||||
}
|
||||
|
||||
// PY-23247
|
||||
public void testHoverOverOverloadsAndImplementation() {
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON35, this::checkHover);
|
||||
}
|
||||
|
||||
// PY-23247
|
||||
public void testDocOnImplementationWithOverloads() {
|
||||
runWithLanguageLevel(
|
||||
LanguageLevel.PYTHON35,
|
||||
() -> {
|
||||
final PsiElement originalElement = loadTest().get("<the_ref>");
|
||||
checkByHTML(myProvider.generateDoc(originalElement.getParent(), originalElement));
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user