PY-30249: For params declared as heterogeneous list -- use union

[1, '2'] means argument is int | str
This commit is contained in:
Ilya.Kazakevich
2018-06-04 19:10:54 +03:00
parent 702b421b72
commit a9de3ce543
4 changed files with 25 additions and 12 deletions
@@ -58,7 +58,8 @@ private fun getParametersFromDecorator(decorator: PyDecorator, evalContext: Type
//Could be union of tuples
val members = iteratedItemType.members
for (i in 0 until parameterTypes.size) {
parameterTypes[i] = PyUnionType.union(members.map { (it as? PyTupleType)?.getElementType(i) })
// If iterated elements is tuple -- open it. Otherwise use as union
parameterTypes[i] = PyUnionType.union(members.map { (it as? PyTupleType)?.getElementType(i) ?: it })
}
}
is PyTupleType -> iteratedItemType.elementTypes.forEachIndexed { i, type -> if (parameterTypes.size > i) parameterTypes[i] = type }
@@ -8,11 +8,17 @@ import pytest
@pytest.mark.parametrize("x", [0, 1])
@pytest.mark.parametrize("y", [2, 3])
def test_returns_correct_result(test_input, expected, x, y): # False positive: unused parameters
y.bit_length()
x.bit_length()
test_input.__len__()
expected.bit_length()
y.bit_length() #
x.bit_length() #
test_input.__len__() #
expected.bit_length() #
@pytest.mark.parametrize(('x', 'y'), [(1, 2, 3, 4)]) # Too many values in tuple, should be 2
def test_wrong_number_of_parameters(x, y):
x.bit_length()
x.bit_length() #
@pytest.mark.parametrize("y", ['2', 3])
def test_foo(y):
y.bit_length() #
y.__xor__( )#
y.upper()#
@@ -8,11 +8,17 @@ import pytest
@pytest.mark.parametrize("x", [0, 1])
@pytest.mark.parametrize("y", [2, 3])
def test_returns_correct_result(test_input, expected, x, y): # False positive: unused parameters
y.bit_len<caret>
x.bit_len<caret>
test_input.len<caret>
expected.bit_len<caret>
y.bit_len<caret>#
x.bit_len<caret>#
test_input.len<caret>#
expected.bit_len<caret>#
@pytest.mark.parametrize(('x', 'y'), [(1, 2, 3, 4)]) # Too many values in tuple, should be 2
def test_wrong_number_of_parameters(x, y):
x.bit_len<caret>
x.bit_len<caret>#
@pytest.mark.parametrize("y", ['2', 3])
def test_foo(y):
y.bit_len<caret>#
y.__xor<caret>#
y.uppe<caret>#
@@ -27,7 +27,7 @@ class PyTestFixtureAndParametrizedTest : PyTestCase() {
fun testTypeCompletion() {
myFixture.copyDirectoryToProject(".", ".")
myFixture.configureByFile("test_parametrized.py")
myFixture.completeBasicAllCarets(null)
myFixture.completeBasicAllCarets('\t')
myFixture.checkResultByFile("after_test_parametrized.txt")
}