From 9a03e524415b77599b18788f1f2dd24c6797fc38 Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Mon, 30 Mar 2015 20:41:08 +0300 Subject: [PATCH] Renamed 't1 | t2 | ...' to 'Union[t1, t2, ...]' according to PEP 484 (PY-15206) --- .../documentation/PyTypeModelBuilder.java | 8 +++-- .../PyTypeCheckerInspection/BuiltinNumeric.py | 2 +- .../PyTypeCheckerInspection/BuiltinsPy3.py | 2 +- .../PyTypeCheckerInspection/DictLiterals.py | 4 +-- .../PyTypeCheckerInspection/Generator.py | 6 ++-- .../PyTypeCheckerInspection/ListTuple.py | 2 +- .../MapReturnElementType.py | 2 +- .../PropertyAndFactoryFunction.py | 2 +- .../PyTypeCheckerInspection/SecondFormIter.py | 2 +- .../PyTypeCheckerInspection/StringInteger.py | 4 +-- .../StringStartsWith.py | 4 +-- .../UnionReturnTypes.py | 2 +- .../WithOpenBinaryPy3.py | 2 +- .../quickdoc/HoverOverControlFlowUnion.html | 2 +- python/testData/quickdoc/Variable.html | 2 +- .../com/jetbrains/python/PyTypeTest.java | 34 +++++++++---------- .../com/jetbrains/python/PyTypingTest.java | 4 +-- 17 files changed, 44 insertions(+), 40 deletions(-) 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('foo', u'bar') pow(False, True) - round(False, 'foo') + round(False, 'foo') diff --git a/python/testData/inspections/PyTypeCheckerInspection/BuiltinsPy3.py b/python/testData/inspections/PyTypeCheckerInspection/BuiltinsPy3.py index 4156d651dae3..67f40dd5e5d4 100644 --- a/python/testData/inspections/PyTypeCheckerInspection/BuiltinsPy3.py +++ b/python/testData/inspections/PyTypeCheckerInspection/BuiltinsPy3.py @@ -13,4 +13,4 @@ def test_numerics(): divmod(False, False) divmod(b'foo', 'bar') pow(False, True) - round(False, 'foo') + round(False, 'foo') diff --git a/python/testData/inspections/PyTypeCheckerInspection/DictLiterals.py b/python/testData/inspections/PyTypeCheckerInspection/DictLiterals.py index eb27a50a033f..d229a0384150 100644 --- a/python/testData/inspections/PyTypeCheckerInspection/DictLiterals.py +++ b/python/testData/inspections/PyTypeCheckerInspection/DictLiterals.py @@ -3,6 +3,6 @@ def test(): for v in xs.values(): print(v + None) for k in xs.keys(): - print(k + None) + print(k + None) for k in xs: - print(k + None) + print(k + None) diff --git a/python/testData/inspections/PyTypeCheckerInspection/Generator.py b/python/testData/inspections/PyTypeCheckerInspection/Generator.py index 7523940a8593..95481a651b42 100644 --- a/python/testData/inspections/PyTypeCheckerInspection/Generator.py +++ b/python/testData/inspections/PyTypeCheckerInspection/Generator.py @@ -89,9 +89,9 @@ def test(): f_8(gen(11)), f_9(gen(11)), f_10(gen(11)), - f_11(gen(11)), - f_12(gen(11)), - f_13(gen(11)), + f_11(gen(11)), + f_12(gen(11)), + f_13(gen(11)), f_14(gen(11)), f_15(gen(11)), f_15('foo'.split('o')), diff --git a/python/testData/inspections/PyTypeCheckerInspection/ListTuple.py b/python/testData/inspections/PyTypeCheckerInspection/ListTuple.py index 2dfd05166f70..e47e9363ce5a 100644 --- a/python/testData/inspections/PyTypeCheckerInspection/ListTuple.py +++ b/python/testData/inspections/PyTypeCheckerInspection/ListTuple.py @@ -7,5 +7,5 @@ def f(spam, eggs): def test(): - f([1, 2, 3], + f([1, 2, 3], (False, 2, '')) diff --git a/python/testData/inspections/PyTypeCheckerInspection/MapReturnElementType.py b/python/testData/inspections/PyTypeCheckerInspection/MapReturnElementType.py index a27266914eed..14563237d69e 100644 --- a/python/testData/inspections/PyTypeCheckerInspection/MapReturnElementType.py +++ b/python/testData/inspections/PyTypeCheckerInspection/MapReturnElementType.py @@ -2,4 +2,4 @@ def test(): xs = map(lambda x: x + 1, [1, 2, 3]) print('foo' + xs[0]) # Can be a str since map returns list[V] | str | unicode ys = map(tuple, iter([1, 2, 3])) - print(1 + ys[0], 'bar' + ys[1]) + print(1 + ys[0], 'bar' + ys[1]) diff --git a/python/testData/inspections/PyTypeCheckerInspection/PropertyAndFactoryFunction.py b/python/testData/inspections/PyTypeCheckerInspection/PropertyAndFactoryFunction.py index 8cf0bfcce4a9..deca51ac5459 100644 --- a/python/testData/inspections/PyTypeCheckerInspection/PropertyAndFactoryFunction.py +++ b/python/testData/inspections/PyTypeCheckerInspection/PropertyAndFactoryFunction.py @@ -7,4 +7,4 @@ def f(): return C() def test(): - f().foo + 1 + f().foo + 1 diff --git a/python/testData/inspections/PyTypeCheckerInspection/SecondFormIter.py b/python/testData/inspections/PyTypeCheckerInspection/SecondFormIter.py index bf0a0e80c6a2..4d2cbf6a7a6b 100644 --- a/python/testData/inspections/PyTypeCheckerInspection/SecondFormIter.py +++ b/python/testData/inspections/PyTypeCheckerInspection/SecondFormIter.py @@ -7,7 +7,7 @@ def test_second_form(): def test_second_form_fail(): - for chunk in iter(10, ''): + for chunk in iter(10, ''): pass diff --git a/python/testData/inspections/PyTypeCheckerInspection/StringInteger.py b/python/testData/inspections/PyTypeCheckerInspection/StringInteger.py index caad34d184ed..6f1e0e418d58 100644 --- a/python/testData/inspections/PyTypeCheckerInspection/StringInteger.py +++ b/python/testData/inspections/PyTypeCheckerInspection/StringInteger.py @@ -1,8 +1,8 @@ def test(): print('foo' + 'bar') print(2 + 3) - print('foo' + 3) + print('foo' + 3) print(3 + 'foo') print('foo' + 'bar' * 3) print('foo' + 3 * 'bar') - print('foo' + 2 * 3) + print('foo' + 2 * 3) diff --git a/python/testData/inspections/PyTypeCheckerInspection/StringStartsWith.py b/python/testData/inspections/PyTypeCheckerInspection/StringStartsWith.py index dae1ba9955e0..7bb15093b687 100644 --- a/python/testData/inspections/PyTypeCheckerInspection/StringStartsWith.py +++ b/python/testData/inspections/PyTypeCheckerInspection/StringStartsWith.py @@ -1,7 +1,7 @@ 'foo'.startswith('bar') 'foo'.startswith(('bar', 'baz')) -'foo'.startswith(2) +'foo'.startswith(2) u'foo'.startswith(u'bar') u'foo'.startswith((u'bar', u'baz')) -u'foo'.startswith(2) +u'foo'.startswith(2) diff --git a/python/testData/inspections/PyTypeCheckerInspection/UnionReturnTypes.py b/python/testData/inspections/PyTypeCheckerInspection/UnionReturnTypes.py index 5c2d00d3b53c..30e2ab7ddda1 100644 --- a/python/testData/inspections/PyTypeCheckerInspection/UnionReturnTypes.py +++ b/python/testData/inspections/PyTypeCheckerInspection/UnionReturnTypes.py @@ -17,7 +17,7 @@ def test(c): """ x1 = f1(c) f2(x1) # Weaker union types - f3(x1) + f3(x1) f2(x1.count('')) f3(x1.count('')) diff --git a/python/testData/inspections/PyTypeCheckerInspection/WithOpenBinaryPy3.py b/python/testData/inspections/PyTypeCheckerInspection/WithOpenBinaryPy3.py index 9198f3f6ea89..7527db0f95f3 100644 --- a/python/testData/inspections/PyTypeCheckerInspection/WithOpenBinaryPy3.py +++ b/python/testData/inspections/PyTypeCheckerInspection/WithOpenBinaryPy3.py @@ -2,4 +2,4 @@ with open('foo', 'wb') as fd: fd.write(b'bar') with open('foo', 'wb') as fd: - fd.write('bar') + fd.write('bar') diff --git a/python/testData/quickdoc/HoverOverControlFlowUnion.html b/python/testData/quickdoc/HoverOverControlFlowUnion.html index 5b9ce6b5ca02..1863ee9781d8 100644 --- a/python/testData/quickdoc/HoverOverControlFlowUnion.html +++ b/python/testData/quickdoc/HoverOverControlFlowUnion.html @@ -1,2 +1,2 @@ variable "x" -Inferred type: str | int +Inferred type: Union[str, int] diff --git a/python/testData/quickdoc/Variable.html b/python/testData/quickdoc/Variable.html index eac55f8d9c13..68812118dd74 100644 --- a/python/testData/quickdoc/Variable.html +++ b/python/testData/quickdoc/Variable.html @@ -1 +1 @@ -Assigned to 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" +