diff --git a/python/src/com/jetbrains/python/psi/impl/PyTryExceptStatementImpl.java b/python/src/com/jetbrains/python/psi/impl/PyTryExceptStatementImpl.java
index ba04db727680..e4fcd01a593c 100644
--- a/python/src/com/jetbrains/python/psi/impl/PyTryExceptStatementImpl.java
+++ b/python/src/com/jetbrains/python/psi/impl/PyTryExceptStatementImpl.java
@@ -96,22 +96,19 @@ public class PyTryExceptStatementImpl extends PyElementImpl implements PyTryExce
@NotNull ResolveState substitutor,
PsiElement lastParent,
@NotNull PsiElement place) {
- if (lastParent != null) {
- return true;
- }
-
- if (!getTryStatementList().processDeclarations(processor, substitutor, null, place)) {
+ final PyStatementList tryStatementList = getTryStatementList();
+ if (tryStatementList != lastParent && !tryStatementList.processDeclarations(processor, substitutor, null, place)) {
return false;
}
for (PyExceptBlock block : getExceptBlocks()) {
- if (!block.processDeclarations(processor, substitutor, null, place)) {
+ if (block != lastParent && !block.processDeclarations(processor, substitutor, null, place)) {
return false;
}
}
PyStatementList elseStatementList = getElseStatementList();
- if (elseStatementList != null) {
+ if (elseStatementList != null && elseStatementList != lastParent) {
return elseStatementList.processDeclarations(processor, substitutor, null, place);
}
return true;
diff --git a/python/testData/highlighting/continueInFinallyBlock.py b/python/testData/highlighting/continueInFinallyBlock.py
index 586fe87155d8..a1615782d8c2 100644
--- a/python/testData/highlighting/continueInFinallyBlock.py
+++ b/python/testData/highlighting/continueInFinallyBlock.py
@@ -1,5 +1,5 @@
while True:
try:
- x
+ print "a"
finally:
continue
\ No newline at end of file
diff --git a/python/testData/resolve/TryExceptElse.py b/python/testData/resolve/TryExceptElse.py
new file mode 100644
index 000000000000..6a8e0d766c7c
--- /dev/null
+++ b/python/testData/resolve/TryExceptElse.py
@@ -0,0 +1,6 @@
+try:
+ name = ""
+except:
+ pass
+else:
+ print na[me
\ No newline at end of file
diff --git a/python/testSrc/com/jetbrains/python/PyResolveTest.java b/python/testSrc/com/jetbrains/python/PyResolveTest.java
index 40e498f3ed06..38ec32666f49 100644
--- a/python/testSrc/com/jetbrains/python/PyResolveTest.java
+++ b/python/testSrc/com/jetbrains/python/PyResolveTest.java
@@ -58,6 +58,11 @@ public class PyResolveTest extends ResolveTestCase {
assertTrue(targetElement instanceof PyTargetExpression);
}
+ public void testTryExceptElse() throws Exception {
+ PsiElement targetElement = resolve();
+ assertTrue(targetElement instanceof PyTargetExpression);
+ }
+
@Override
protected String getTestDataPath() {
return PathManager.getHomePath() + "/plugins/python/testData/resolve/";
]