diff --git a/python/src/com/jetbrains/python/psi/impl/PyReferenceExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyReferenceExpressionImpl.java index 12b6052614de..cb3867b968be 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyReferenceExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyReferenceExpressionImpl.java @@ -252,7 +252,7 @@ public class PyReferenceExpressionImpl extends PyElementImpl implements PyRefere if (target instanceof PyImportedModule) { return new PyImportedModuleType((PyImportedModule)target); } - if ((target instanceof PyTargetExpression | target instanceof PyNamedParameter) && context.allowDataFlow() && anchor != null) { + if ((target instanceof PyTargetExpression || target instanceof PyNamedParameter) && context.allowDataFlow() && anchor != null) { final ScopeOwner scopeOwner = PsiTreeUtil.getParentOfType(anchor, ScopeOwner.class); if (scopeOwner != null && scopeOwner == PsiTreeUtil.getParentOfType(target, ScopeOwner.class)) { PyAugAssignmentStatement augAssignment = PsiTreeUtil.getParentOfType(anchor, PyAugAssignmentStatement.class); diff --git a/python/src/com/jetbrains/python/psi/impl/PyReferenceImpl.java b/python/src/com/jetbrains/python/psi/impl/PyReferenceImpl.java index eee0320122d1..b7c69f2f916a 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyReferenceImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyReferenceImpl.java @@ -15,14 +15,12 @@ import com.intellij.util.Icons; import com.intellij.util.IncorrectOperationException; import com.intellij.util.containers.SortedList; import com.jetbrains.python.PyNames; -import com.jetbrains.python.codeInsight.controlflow.ScopeOwner; import com.jetbrains.python.psi.*; import com.jetbrains.python.psi.resolve.*; import com.jetbrains.python.psi.search.PySuperMethodsSearch; import com.jetbrains.python.psi.types.PyModuleType; import com.jetbrains.python.psi.types.PyType; import com.jetbrains.python.psi.types.TypeEvalContext; -import com.jetbrains.python.refactoring.PyDefUseUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -179,26 +177,6 @@ public class PyReferenceImpl implements PsiReferenceEx, PsiPolyVariantReference } if (roof == null) roof = realContext.getContainingFile(); PsiElement uexpr = PyResolveUtil.treeCrawlUp(processor, false, realContext, roof); - if (uexpr != null) { - //add possible inferred types - if ((uexpr instanceof PyTargetExpression || uexpr instanceof PyNamedParameter) && myElement != null) { - final ScopeOwner scopeOwner = PsiTreeUtil.getParentOfType(myElement, ScopeOwner.class); - if (scopeOwner != null && scopeOwner == PsiTreeUtil.getStubOrPsiParentOfType(uexpr, ScopeOwner.class)) { - PyAugAssignmentStatement augAssignment = PsiTreeUtil.getParentOfType(myElement, PyAugAssignmentStatement.class); - try { - final PyElement[] defs = PyDefUseUtil.getLatestDefs(scopeOwner, (PyElement)uexpr, - augAssignment != null ? augAssignment : myElement); - for (PyElement e : defs) { - ret.add(new RatedResolveResult(RatedResolveResult.RATE_NORMAL + 1, e)); - } - } - catch (PyDefUseUtil.InstructionNotFoundException e) { - // ignore - } - } - } - - } if ((uexpr != null)) { if ((uexpr instanceof PyClass)) { // is it a case of the bizarre "class Foo(Foo)" construct? diff --git a/python/testData/completion/isInstance.after.py b/python/testData/completion/isInstance.after.py new file mode 100644 index 000000000000..81a1b1b2064e --- /dev/null +++ b/python/testData/completion/isInstance.after.py @@ -0,0 +1,6 @@ +class Foo: + def xyzzy(self): pass + +def x(p): + if isinstance(p, Foo): + p.xyzzy() diff --git a/python/testData/completion/isInstance.py b/python/testData/completion/isInstance.py new file mode 100644 index 000000000000..5a7408e4e913 --- /dev/null +++ b/python/testData/completion/isInstance.py @@ -0,0 +1,6 @@ +class Foo: + def xyzzy(self): pass + +def x(p): + if isinstance(p, Foo): + p.xy diff --git a/python/testData/completion/isInstanceAssert.after.py b/python/testData/completion/isInstanceAssert.after.py new file mode 100644 index 000000000000..b297d2ff0274 --- /dev/null +++ b/python/testData/completion/isInstanceAssert.after.py @@ -0,0 +1,8 @@ +class Foo: + def xyzzy(self): pass + +def bar(): pass + +f = bar() +assert isinstance(f, Foo) +f.xyzzy() \ No newline at end of file diff --git a/python/testData/completion/isInstanceAssert.py b/python/testData/completion/isInstanceAssert.py new file mode 100644 index 000000000000..4c36384922da --- /dev/null +++ b/python/testData/completion/isInstanceAssert.py @@ -0,0 +1,8 @@ +class Foo: + def xyzzy(self): pass + +def bar(): pass + +f = bar() +assert isinstance(f, Foo) +f.xy \ No newline at end of file diff --git a/python/testData/resolve/IsInstance.py b/python/testData/resolve/IsInstance.py new file mode 100644 index 000000000000..e95a1e28c05a --- /dev/null +++ b/python/testData/resolve/IsInstance.py @@ -0,0 +1,3 @@ +def my_func(my_arg): + assert isinstance(my_arg, basestring) + print my_arg \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyControlFlowBuilderTest.java b/python/testSrc/com/jetbrains/python/PyControlFlowBuilderTest.java index 4893d6583d78..995f3591c632 100644 --- a/python/testSrc/com/jetbrains/python/PyControlFlowBuilderTest.java +++ b/python/testSrc/com/jetbrains/python/PyControlFlowBuilderTest.java @@ -26,7 +26,7 @@ public class PyControlFlowBuilderTest extends LightMarkedTestCase { private void doTest() throws Exception { final String testName = getTestName(false).toLowerCase(); configureByFile(testName + ".py"); - final ControlFlow flow = ((PyFile)myFile).getControlFlow(); + final ControlFlow flow = ((PyFile)myFile).getControlFlow(); final String fullPath = getTestDataPath() + testName + ".txt"; check(fullPath, flow); } @@ -38,7 +38,7 @@ public class PyControlFlowBuilderTest extends LightMarkedTestCase { public void testFile() throws Exception { doTest(); } - + public void testIf() throws Exception { doTest(); } @@ -152,7 +152,7 @@ public class PyControlFlowBuilderTest extends LightMarkedTestCase { check(fullPath, flow); } - private void check(final String fullPath, final ControlFlow flow) throws IOException { + private static void check(final String fullPath, final ControlFlow flow) throws IOException { final StringBuffer buffer = new StringBuffer(); final Instruction[] instructions = flow.getInstructions(); for (Instruction instruction : instructions) { diff --git a/python/testSrc/com/jetbrains/python/PyResolveTest.java b/python/testSrc/com/jetbrains/python/PyResolveTest.java index b1f711b4ee8a..23a4f9a39243 100644 --- a/python/testSrc/com/jetbrains/python/PyResolveTest.java +++ b/python/testSrc/com/jetbrains/python/PyResolveTest.java @@ -309,4 +309,9 @@ public class PyResolveTest extends PyResolveTestCase { ImportedResolveResult result = (ImportedResolveResult) results [0]; assertNull(result.getElement()); } + + public void testIsInstance() { // PY-1133 + PsiElement targetElement = resolve(); + assertInstanceOf(targetElement, PyNamedParameter.class); + } } \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PythonCompletionTest.java b/python/testSrc/com/jetbrains/python/PythonCompletionTest.java index da6cd371ac45..8cd1e1497af5 100644 --- a/python/testSrc/com/jetbrains/python/PythonCompletionTest.java +++ b/python/testSrc/com/jetbrains/python/PythonCompletionTest.java @@ -99,6 +99,14 @@ public class PythonCompletionTest extends PyLightFixtureTestCase { doTest(); } + public void testIsInstance() throws Exception { + doTest(); + } + + public void testIsInstanceAssert() throws Exception { + doTest(); + } + public void testImportModule() throws Exception { final String testName = "completion/" + getTestName(true); myFixture.configureByFiles(testName + ".py", "completion/someModule.py"); diff --git a/python/testSrc/com/jetbrains/python/fixtures/LightMarkedTestCase.java b/python/testSrc/com/jetbrains/python/fixtures/LightMarkedTestCase.java index 479e1474c7be..87ad28b671a4 100644 --- a/python/testSrc/com/jetbrains/python/fixtures/LightMarkedTestCase.java +++ b/python/testSrc/com/jetbrains/python/fixtures/LightMarkedTestCase.java @@ -37,7 +37,7 @@ public abstract class LightMarkedTestCase extends PyLightFixtureTestCase { * @return a mapping of markers to PSI elements * @throws Exception */ - protected Map configureByFile(@NonNls String filePath) throws Exception { + protected Map configureByFile(@TestDataFile @NonNls String filePath) throws Exception { return configureByFile(filePath, MARKER); }