diff --git a/python/src/com/jetbrains/python/documentation/PyTypeModelBuilder.java b/python/src/com/jetbrains/python/documentation/PyTypeModelBuilder.java
index 4dd9eddc35aa..e40bb820cf14 100644
--- a/python/src/com/jetbrains/python/documentation/PyTypeModelBuilder.java
+++ b/python/src/com/jetbrains/python/documentation/PyTypeModelBuilder.java
@@ -266,9 +266,11 @@ public class PyTypeModelBuilder {
public void unknown(UnknownType type) {
final TypeModel nested = type.type;
if (nested != null) {
+ add("Union[");
nested.accept(this);
+ add(", " + PyNames.UNKNOWN_TYPE);
+ add("]");
}
- add(" | " + PyNames.UNKNOWN_TYPE);
}
}
@@ -310,7 +312,9 @@ public class PyTypeModelBuilder {
add("...");
return;
}
- processList(oneOf.oneOfTypes, " | ");
+ add("Union[");
+ processList(oneOf.oneOfTypes, ", ");
+ add("]");
myDepth--;
}
diff --git a/python/testData/inspections/PyTypeCheckerInspection/BuiltinNumeric.py b/python/testData/inspections/PyTypeCheckerInspection/BuiltinNumeric.py
index b44e59bdc4bc..8bfe76196b43 100644
--- a/python/testData/inspections/PyTypeCheckerInspection/BuiltinNumeric.py
+++ b/python/testData/inspections/PyTypeCheckerInspection/BuiltinNumeric.py
@@ -7,4 +7,4 @@ def test():
divmod(False, False)
divmod(
y
Inferred type: int | str
+Assigned to y
Inferred type: Union[int, str]
diff --git a/python/testSrc/com/jetbrains/python/PyTypeTest.java b/python/testSrc/com/jetbrains/python/PyTypeTest.java
index 3f1bb071fe94..a382972245a9 100644
--- a/python/testSrc/com/jetbrains/python/PyTypeTest.java
+++ b/python/testSrc/com/jetbrains/python/PyTypeTest.java
@@ -42,9 +42,9 @@ public class PyTypeTest extends PyTestCase {
public void testBinaryExprType() {
doTest("int",
"expr = 1 + 2");
- doTest("str | unicode",
+ doTest("Union[str, unicode]",
"expr = '1' + '2'");
- doTest("str | unicode",
+ doTest("Union[str, unicode]",
"expr = '%s' % ('a')");
doTest("list[int]",
"expr = [1] + [2]");
@@ -238,7 +238,7 @@ public class PyTypeTest extends PyTestCase {
}
public void testUnknownTypeInUnion() {
- doTest("int | Any",
+ doTest("Union[int, Any]",
"def f(c, x):\n" +
" if c:\n" +
" return 1\n" +
@@ -361,7 +361,7 @@ public class PyTypeTest extends PyTestCase {
public void testYieldFromType() {
PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), LanguageLevel.PYTHON33);
try {
- doTest("str | int | float",
+ doTest("Union[str, int, float]",
"def subgen():\n" +
" for i in [1, 2, 3]:\n" +
" yield i\n" +
@@ -570,7 +570,7 @@ public class PyTypeTest extends PyTestCase {
}
public void testLogicalAndExpression() {
- doTest("str | int",
+ doTest("Union[str, int]",
"expr = 'foo' and 2");
}
@@ -596,11 +596,11 @@ public class PyTypeTest extends PyTestCase {
" foo(3)\n" +
" foo('bar')\n";
final PyExpression expr = parseExpr(text);
- doTest("int | str | Any", expr, TypeEvalContext.codeCompletion(expr.getProject(), expr.getContainingFile()));
+ doTest("Union[Union[int, str], Any]", expr, TypeEvalContext.codeCompletion(expr.getProject(), expr.getContainingFile()));
}
public void testUpperBoundGeneric() {
- doTest("int | str",
+ doTest("Union[int, str]",
"def foo(x):\n" +
" '''\n" +
" :type x: T <= int or str\n" +
@@ -622,7 +622,7 @@ public class PyTypeTest extends PyTestCase {
}
public void testFunctionTypeAsUnificationArgument() {
- doTest("list[int] | str | unicode",
+ doTest("Union[list[int], str, unicode]",
"def map2(f, xs):\n" +
" '''\n" +
" :type f: (T) -> V | None\n" +
@@ -635,7 +635,7 @@ public class PyTypeTest extends PyTestCase {
}
public void testFunctionTypeAsUnificationArgumentWithSubscription() {
- doTest("int | str | unicode",
+ doTest("Union[int, str, unicode]",
"def map2(f, xs):\n" +
" '''\n" +
" :type f: (T) -> V | None\n" +
@@ -764,7 +764,7 @@ public class PyTypeTest extends PyTestCase {
}
public void testNoResolveToFunctionsInTypes() {
- doTest("C | Any",
+ doTest("Union[C, Any]",
"class C(object):\n" +
" def bar(self):\n" +
" pass\n" +
@@ -777,7 +777,7 @@ public class PyTypeTest extends PyTestCase {
}
public void testIsInstanceExpressionResolvedToTuple() {
- doTest("str | unicode",
+ doTest("Union[str, unicode]",
"string_types = str, unicode\n" +
"\n" +
"def f(x):\n" +
@@ -786,7 +786,7 @@ public class PyTypeTest extends PyTestCase {
}
public void testIsInstanceInConditionalExpression() {
- doTest("str | int",
+ doTest("Union[str, int]",
"def f(x):\n" +
" expr = x if isinstance(x, str) else 10\n");
}
@@ -837,7 +837,7 @@ public class PyTypeTest extends PyTestCase {
}
public void testTupleIterationType() {
- doTest("int | str",
+ doTest("Union[int, str]",
"xs = (1, 'a')\n" +
"for expr in xs:\n" +
" pass\n");
@@ -900,7 +900,7 @@ public class PyTypeTest extends PyTestCase {
}
public void testUnionTypeAttributeOfDifferentTypes() {
- doTest("list | int",
+ doTest("Union[list, int]",
"class Foo:\n" +
" x = []\n" +
"\n" +
@@ -914,7 +914,7 @@ public class PyTypeTest extends PyTestCase {
// PY-11364
public void testUnionTypeAttributeCallOfDifferentTypes() {
- doTest("C1 | C2",
+ doTest("Union[C1, C2]",
"class C1:\n" +
" def foo(self):\n" +
" return self\n" +
@@ -934,7 +934,7 @@ public class PyTypeTest extends PyTestCase {
// PY-12862
public void testUnionTypeAttributeSubscriptionOfDifferentTypes() {
- doTest("C1 | C2",
+ doTest("Union[C1, C2]",
"class C1:\n" +
" def __getitem__(self, item):\n" +
" return self\n" +
@@ -955,7 +955,7 @@ public class PyTypeTest extends PyTestCase {
// PY-11541
public void testIsInstanceBaseStringCheck() {
- doTest("str | unicode",
+ doTest("Union[str, unicode]",
"def f(x):\n" +
" if isinstance(x, basestring):\n" +
" expr = x\n");
diff --git a/python/testSrc/com/jetbrains/python/PyTypingTest.java b/python/testSrc/com/jetbrains/python/PyTypingTest.java
index 3d4c95085274..a1114b4e5e98 100644
--- a/python/testSrc/com/jetbrains/python/PyTypingTest.java
+++ b/python/testSrc/com/jetbrains/python/PyTypingTest.java
@@ -84,7 +84,7 @@ public class PyTypingTest extends PyTestCase {
}
public void testUnionType() {
- doTest("int | str",
+ doTest("Union[int, str]",
"from typing import Union\n" +
"\n" +
"def f(expr: Union[int, str]):\n" +
@@ -214,7 +214,7 @@ public class PyTypingTest extends PyTestCase {
}
public void testAnyStrForUnknown() {
- doTest("bytes | str",
+ doTest("Union[bytes, str]",
"from typing import AnyStr\n" +
"\n" +
"def foo(x: AnyStr) -> AnyStr:\n" +