mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-17705 Fixed: Awkward formatting of parameter types in Quick Documentation for io.open()
Don't forget to cache type if it was converted to Optional
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.documentation;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -26,10 +25,7 @@ import com.jetbrains.python.toolbox.ChainIterable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import static com.jetbrains.python.documentation.DocumentationBuilderKit.$;
|
||||
import static com.jetbrains.python.documentation.DocumentationBuilderKit.combUp;
|
||||
@@ -227,17 +223,10 @@ public class PyTypeModelBuilder {
|
||||
result = new UnknownType(build(unionType.excludeNull(myContext), true));
|
||||
}
|
||||
else {
|
||||
final PyType optionalType = getOptionalType(unionType);
|
||||
if (optionalType != null) {
|
||||
return new OptionalType(build(optionalType, true));
|
||||
}
|
||||
|
||||
result = new OneOf(Collections2.transform(unionType.getMembers(), new Function<PyType, TypeModel>() {
|
||||
@Override
|
||||
public TypeModel apply(PyType t) {
|
||||
return build(t, false);
|
||||
}
|
||||
}));
|
||||
result = Optional
|
||||
.ofNullable(getOptionalType(unionType))
|
||||
.<PyTypeModelBuilder.TypeModel>map(optionalType -> new OptionalType(build(optionalType, true)))
|
||||
.orElseGet(() -> new OneOf(Collections2.transform(unionType.getMembers(), t -> build(t, false))));
|
||||
}
|
||||
}
|
||||
else if (type instanceof PyCallableType && !(type instanceof PyClassLikeType)) {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<html><body><code>def <b>open</b>(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)<br>Inferred type: (file: <a href="psi_element://#typename#str">str</a>, mode: <a href="psi_element://#typename#str">str</a>, buffering: Integral, encoding: Optional[<a href="psi_element://#typename#str">str</a>], errors: Optional[<a href="psi_element://#typename#str">str</a>], newline: Optional[<a href="psi_element://#typename#str">str</a>], closefd: <a href="psi_element://#typename#bool">bool</a>, opener: Optional[(<a href="psi_element://#typename#str">str</a>, <a href="psi_element://#typename#int">int</a>) -> <a href="psi_element://#typename#int">int</a>]) -> Union[FileIO[<a href="psi_element://#typename#str">str</a>], TextIOWrapper[<a href="psi_element://#typename#unicode">unicode</a>]]<br><br></code>This is an alias for the builtin open() function.<br/><br/></body></html>
|
||||
@@ -0,0 +1,16 @@
|
||||
def open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None):
|
||||
"""This is an alias for the builtin open() function.
|
||||
|
||||
:type file: str
|
||||
:type mode: str
|
||||
:type buffering: numbers.Integral
|
||||
:type encoding: str | None
|
||||
:type errors: str | None
|
||||
:type newline: str | None
|
||||
:type closefd: bool
|
||||
:type opener: ((str, int) -> int) | None
|
||||
:rtype: io.FileIO[bytes] | io.TextIOWrapper[unicode]
|
||||
"""
|
||||
pass
|
||||
|
||||
<the_ref>open("service")
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -260,4 +260,9 @@ public class PyQuickDocTest extends LightMarkedTestCase {
|
||||
myFixture.copyDirectoryToProject("/quickdoc/" + getTestName(false), "");
|
||||
checkHover();
|
||||
}
|
||||
|
||||
// PY-17705
|
||||
public void testOptionalParameterType() {
|
||||
checkHTMLOnly();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user