PY-20057 Render the type of "type" class as just "type" instead of "Type[type]"

This commit is contained in:
Mikhail Golubev
2017-03-06 15:20:44 +03:00
parent 9ce723de0d
commit 1bce2d9bf5
2 changed files with 11 additions and 3 deletions
@@ -21,6 +21,7 @@ import com.intellij.psi.PsiElement;
import com.intellij.util.containers.ContainerUtil;
import com.jetbrains.python.PyNames;
import com.jetbrains.python.codeInsight.typing.PyTypingTypeProvider;
import com.jetbrains.python.psi.impl.PyBuiltinCache;
import com.jetbrains.python.psi.types.*;
import com.jetbrains.python.toolbox.ChainIterable;
import org.jetbrains.annotations.NotNull;
@@ -280,7 +281,14 @@ public class PyTypeModelBuilder {
result = buildCallable((PyCallableType)type);
}
else if (type instanceof PyInstantiableType && ((PyInstantiableType)type).isDefinition()) {
result = new ClassObjectType(build(((PyInstantiableType)type).toInstance(), allowUnions));
final PyInstantiableType instanceType = ((PyInstantiableType)type).toInstance();
// Special case: render Type[type] as just type
if (type instanceof PyClassType && instanceType.equals(PyBuiltinCache.getInstance(((PyClassType)type).getPyClass()).getTypeType())) {
result = NamedType.nameOrAny(type);
}
else {
result = new ClassObjectType(build(instanceType, allowUnions));
}
}
else if (type instanceof PyGenericType) {
//assert !((PyGenericType)type).isDefinition()
@@ -32,9 +32,9 @@ expects_type(type)
expects_type(object)
expects_typing_type(type)
expects_typing_type(object)
expects_str_class(<warning descr="Expected type 'Type[str]', got 'Type[type]' instead">type</warning>)
expects_str_class(<warning descr="Expected type 'Type[str]', got 'type' instead">type</warning>)
expects_any_type_via_type_var(type)
expects_str_subclass(<warning descr="Expected type 'Type[TypeVar('T', str)]', got 'Type[type]' instead">type</warning>)
expects_str_subclass(<warning descr="Expected type 'Type[TypeVar('T', str)]', got 'type' instead">type</warning>)
expects_object(type)