Use TypeEvalContext.userInitiated() for replace tuple with list quickfix (PY-15558)
authorAndrey Vlasovskikh <andrey.vlasovskikh@jetbrains.com>
Mon, 16 Nov 2015 16:25:58 +0000 (19:25 +0300)
committerAndrey Vlasovskikh <andrey.vlasovskikh@jetbrains.com>
Mon, 16 Nov 2015 16:25:58 +0000 (19:25 +0300)
The default type evaluation context doesn't allow to perform proper
follow assignments chain even for AST-based trees now (which is
consistent with stub-based trees). We have to specify the appropriate
context manually.

python/src/com/jetbrains/python/inspections/quickfix/PyReplaceTupleWithListQuickFix.java

index d480d339bb36ce619315bd8d25bb5c61860ce75e..53254e72e2e75d82404de593ec2f84e1496a13a1 100644 (file)
@@ -22,6 +22,7 @@ import com.intellij.psi.PsiElement;
 import com.jetbrains.python.PyBundle;
 import com.jetbrains.python.psi.*;
 import com.jetbrains.python.psi.resolve.PyResolveContext;
+import com.jetbrains.python.psi.types.TypeEvalContext;
 import org.jetbrains.annotations.NotNull;
 
 public class PyReplaceTupleWithListQuickFix implements LocalQuickFix {
@@ -46,7 +47,9 @@ public class PyReplaceTupleWithListQuickFix implements LocalQuickFix {
       PySubscriptionExpression subscriptionExpression = (PySubscriptionExpression)targets[0];
       if (subscriptionExpression.getOperand() instanceof PyReferenceExpression) {
         PyReferenceExpression referenceExpression = (PyReferenceExpression)subscriptionExpression.getOperand();
-        element = referenceExpression.followAssignmentsChain(PyResolveContext.defaultContext()).getElement();
+        final TypeEvalContext context = TypeEvalContext.userInitiated(project, element.getContainingFile());
+        final PyResolveContext resolveContext = PyResolveContext.noImplicits().withTypeEvalContext(context);
+        element = referenceExpression.followAssignmentsChain(resolveContext).getElement();
         if (element instanceof PyParenthesizedExpression) {
           final PyExpression expression = ((PyParenthesizedExpression)element).getContainedExpression();
           replaceWithListLiteral(element, (PyTupleExpression)expression);