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:
Semyon Proshev
2016-06-17 18:40:15 +03:00
parent 87500300cb
commit 87f0be9f32
4 changed files with 29 additions and 18 deletions
@@ -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,&nbsp;mode='r',&nbsp;buffering=-1,&nbsp;encoding=None,&nbsp;errors=None,&nbsp;newline=None,&nbsp;closefd=True,&nbsp;opener=None)<br>Inferred&nbsp;type:&nbsp;(file:&nbsp;<a href="psi_element://#typename#str">str</a>,&nbsp;mode:&nbsp;<a href="psi_element://#typename#str">str</a>,&nbsp;buffering:&nbsp;Integral,&nbsp;encoding:&nbsp;Optional[<a href="psi_element://#typename#str">str</a>],&nbsp;errors:&nbsp;Optional[<a href="psi_element://#typename#str">str</a>],&nbsp;newline:&nbsp;Optional[<a href="psi_element://#typename#str">str</a>],&nbsp;closefd:&nbsp;<a href="psi_element://#typename#bool">bool</a>,&nbsp;opener:&nbsp;Optional[(<a href="psi_element://#typename#str">str</a>,&nbsp;<a href="psi_element://#typename#int">int</a>)&nbsp;-&gt;&nbsp;<a href="psi_element://#typename#int">int</a>])&nbsp;-&gt;&nbsp;Union[FileIO[<a href="psi_element://#typename#str">str</a>],&nbsp;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();
}
}