diff --git a/python/src/com/jetbrains/python/codeInsight/regexp/PythonRegexpInjector.java b/python/src/com/jetbrains/python/codeInsight/regexp/PythonRegexpInjector.java index 481dd37f4481..fa84794a1aa2 100644 --- a/python/src/com/jetbrains/python/codeInsight/regexp/PythonRegexpInjector.java +++ b/python/src/com/jetbrains/python/codeInsight/regexp/PythonRegexpInjector.java @@ -30,6 +30,7 @@ import com.jetbrains.python.codeInsight.PyInjectionUtil; import com.jetbrains.python.codeInsight.dataflow.scope.ScopeUtil; import com.jetbrains.python.psi.*; import com.jetbrains.python.psi.resolve.PyResolveContext; +import com.jetbrains.python.psi.types.TypeEvalContext; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -89,7 +90,8 @@ public class PythonRegexpInjector implements MultiHostInjector { if (callee instanceof PyReferenceExpression && canBeRegexpCall(callee)) { final PyReferenceExpression referenceExpression = (PyReferenceExpression)callee; - return referenceExpression.getReference(PyResolveContext.noImplicits()).resolve(); + final TypeEvalContext context = TypeEvalContext.codeAnalysis(call.getProject(), call.getContainingFile()); + return referenceExpression.getReference(PyResolveContext.noImplicits().withTypeEvalContext(context)).resolve(); } return null; diff --git a/python/src/com/jetbrains/python/psi/impl/PyReferenceExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyReferenceExpressionImpl.java index cd31bbbddafb..5287d11bdbf7 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyReferenceExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyReferenceExpressionImpl.java @@ -285,16 +285,18 @@ public class PyReferenceExpressionImpl extends PyElementImpl implements PyRefere final PyResolveContext resolveContext = PyResolveContext.noImplicits().withTypeEvalContext(context); final List members = new ArrayList<>(); - for (PsiElement target : PyUtil.multiResolveTopPriority(getReference(resolveContext))) { - if (target == this || target == null) { - continue; - } + if (context.maySwitchToAST(this)) { + for (PsiElement target : PyUtil.multiResolveTopPriority(getReference(resolveContext))) { + if (target == this || target == null) { + continue; + } - if (!target.isValid()) { - throw new PsiInvalidElementAccessException(this); - } + if (!target.isValid()) { + throw new PsiInvalidElementAccessException(this); + } - members.add(getTypeFromTarget(target, context, this)); + members.add(getTypeFromTarget(target, context, this)); + } } return PyUnionType.union(members);