diff --git a/python/src/com/jetbrains/python/psi/NameDefiner.java b/python/src/com/jetbrains/python/psi/NameDefiner.java index 9fd618fb9005..4aee0ac91f70 100644 --- a/python/src/com/jetbrains/python/psi/NameDefiner.java +++ b/python/src/com/jetbrains/python/psi/NameDefiner.java @@ -127,9 +127,13 @@ public interface NameDefiner extends PsiElement { public static PyElement findName(Iterable it, String name) { PyElement ret = null; for (PyElement elt : it) { - if ((elt != null) && (name.equals(elt.getName()))) { - ret = elt; - break; + if (elt != null) { + // qualified refs don't match by last name, and we're not checking FQNs here + if (elt instanceof PyQualifiedExpression && ((PyQualifiedExpression)elt).getQualifier() != null) continue; + if (name.equals(elt.getName())) { // plain name matches + ret = elt; + break; + } } } return ret; diff --git a/python/src/com/jetbrains/python/psi/impl/PyReferenceExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyReferenceExpressionImpl.java index 1c1169e601a4..93e10013afbf 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyReferenceExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyReferenceExpressionImpl.java @@ -320,6 +320,8 @@ public class PyReferenceExpressionImpl extends PyElementImpl implements PyRefere return ret.toArray(new ResolveResult[ret.size()]); } + private static boolean USE_CACHE = true; // change to false in debug time to switch off caching + /** * Resolves reference to possible referred elements. * First element is always what resolve() would return. @@ -332,7 +334,7 @@ public class PyReferenceExpressionImpl extends PyElementImpl implements PyRefere @NotNull public ResolveResult[] multiResolve(final boolean incompleteCode) { final PsiManager manager = getElement().getManager(); - if (manager instanceof PsiManagerImpl) { + if (USE_CACHE && manager instanceof PsiManagerImpl) { final ResolveCache cache = ((PsiManagerImpl)manager).getResolveCache(); return cache.resolveWithCaching(this, CachingResolver.INSTANCE, false, incompleteCode); } diff --git a/python/testData/resolve/QualifiedFalseTarget.py b/python/testData/resolve/QualifiedFalseTarget.py new file mode 100644 index 000000000000..763f391cd0ab --- /dev/null +++ b/python/testData/resolve/QualifiedFalseTarget.py @@ -0,0 +1,7 @@ +class Bobobo: + zoo = 1 + +b = Bobobo() +b.zoo = 2 + +zoo # must not resolve diff --git a/python/testSrc/com/jetbrains/python/PyResolveTest.java b/python/testSrc/com/jetbrains/python/PyResolveTest.java index 8dfa75846226..f0d9138c4ce4 100644 --- a/python/testSrc/com/jetbrains/python/PyResolveTest.java +++ b/python/testSrc/com/jetbrains/python/PyResolveTest.java @@ -88,6 +88,11 @@ public class PyResolveTest extends ResolveTestCase { assertTrue(targetElement instanceof PyTargetExpression); } + public void testQualifiedFalseTarget() throws Exception { + PsiElement targetElement = resolve(); + assertNull(targetElement); + } + public void testInnerFuncVar() throws Exception { PsiElement targetElement = resolve(); assertTrue(targetElement instanceof PyTargetExpression);