mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fixed assignment balance inspection for sliced tuples (PY-6315)
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package com.jetbrains.python.psi;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public interface PySliceExpression extends PyExpression {
|
||||
@NotNull
|
||||
PyExpression getOperand();
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -2,11 +2,11 @@ package com.jetbrains.python.psi.impl;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.jetbrains.python.PyElementTypes;
|
||||
import com.jetbrains.python.PythonDialectsTokenSetProvider;
|
||||
import com.jetbrains.python.psi.PyExpression;
|
||||
import com.jetbrains.python.psi.PySliceExpression;
|
||||
import com.jetbrains.python.psi.PySliceItem;
|
||||
import com.jetbrains.python.psi.types.PyTupleType;
|
||||
import com.jetbrains.python.psi.types.PyType;
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -20,15 +20,25 @@ public class PySliceExpressionImpl extends PyElementImpl implements PySliceExpre
|
||||
super(astNode);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PyType getType(@NotNull TypeEvalContext context) {
|
||||
return context.getType(getOperand());
|
||||
final PyType type = context.getType(getOperand());
|
||||
// TODO: Currently we don't evaluate the static range of the slice, so we have to return a generic tuple type without elements
|
||||
if (type instanceof PyTupleType) {
|
||||
return PyBuiltinCache.getInstance(this).getTupleType();
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PyExpression getOperand() {
|
||||
return childToPsiNotNull(PythonDialectsTokenSetProvider.INSTANCE.getExpressionTokens(), 0);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PySliceItem getSliceItem() {
|
||||
return PsiTreeUtil.getChildOfType(this, PySliceItem.class);
|
||||
}
|
||||
|
||||
@@ -12,4 +12,10 @@ a, b = <warning descr="Too many values to unpack">c</warning>
|
||||
a, b = <warning descr="Too many values to unpack">[1, 2, 3]</warning>
|
||||
a, b = <warning descr="Too many values to unpack">'str'</warning>
|
||||
a, b = <warning descr="Too many values to unpack">{1, 2, 3}</warning>
|
||||
a, b = <warning descr="Too many values to unpack">{1:2, 2: 3, 3:4}</warning>
|
||||
a, b = <warning descr="Too many values to unpack">{1:2, 2: 3, 3:4}</warning>
|
||||
|
||||
# PY-6315
|
||||
def test_tuple_slice():
|
||||
def f():
|
||||
return 1, 2, 3
|
||||
x, y = f()[:2]
|
||||
|
||||
Reference in New Issue
Block a user