diff --git a/python/src/com/jetbrains/python/psi/PyExceptPart.java b/python/src/com/jetbrains/python/psi/PyExceptPart.java index 7d117b0189a9..19c9b8cd9bba 100644 --- a/python/src/com/jetbrains/python/psi/PyExceptPart.java +++ b/python/src/com/jetbrains/python/psi/PyExceptPart.java @@ -1,29 +1,9 @@ -/* - * Copyright 2005 Pythonid Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS"; BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package com.jetbrains.python.psi; import org.jetbrains.annotations.Nullable; /** - * Created by IntelliJ IDEA. - * User: yole - * Date: 02.06.2005 - * Time: 23:37:32 - * To change this template use File | Settings | File Templates. + * @author dcheryasov */ public interface PyExceptPart extends PyElement, NameDefiner, PyStatementPart { PyExceptPart[] EMPTY_ARRAY = new PyExceptPart[0]; diff --git a/python/src/com/jetbrains/python/psi/PyUtil.java b/python/src/com/jetbrains/python/psi/PyUtil.java index 953b9e5e29e6..8f62686caf87 100644 --- a/python/src/com/jetbrains/python/psi/PyUtil.java +++ b/python/src/com/jetbrains/python/psi/PyUtil.java @@ -33,9 +33,7 @@ import com.intellij.util.containers.HashSet; import com.jetbrains.python.PyNames; import com.jetbrains.python.PyTokenTypes; import com.jetbrains.python.PythonLanguage; -import static com.jetbrains.python.psi.PyFunction.Flag.*; import com.jetbrains.python.psi.impl.PyBuiltinCache; -import static com.jetbrains.python.psi.impl.PyCallExpressionHelper.interpretAsStaticmethodOrClassmethodWrappingCall; import com.jetbrains.python.psi.types.PyClassType; import com.jetbrains.python.psi.types.PyType; import org.jetbrains.annotations.NonNls; @@ -47,6 +45,9 @@ import java.awt.*; import java.util.*; import java.util.List; +import static com.jetbrains.python.psi.PyFunction.Flag.*; +import static com.jetbrains.python.psi.impl.PyCallExpressionHelper.interpretAsStaticmethodOrClassmethodWrappingCall; + public class PyUtil { private PyUtil() { } @@ -251,7 +252,7 @@ public class PyUtil { * @return the list of flattened expressions. */ @NotNull - public static List flattenedParens(T[] targets) { + public static List flattenedParens(T... targets) { return _unfoldParenExprs(targets, new ArrayList(targets.length)); } diff --git a/python/src/com/jetbrains/python/psi/impl/PyExceptPartImpl.java b/python/src/com/jetbrains/python/psi/impl/PyExceptPartImpl.java index 8e8403062e4c..09796bb2247f 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyExceptPartImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyExceptPartImpl.java @@ -3,7 +3,6 @@ package com.jetbrains.python.psi.impl; import com.intellij.lang.ASTNode; import com.jetbrains.python.PyElementTypes; import com.jetbrains.python.psi.*; -import com.jetbrains.python.toolbox.SingleIterable; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -33,12 +32,11 @@ public class PyExceptPartImpl extends PyElementImpl implements PyExceptPart { @NotNull public Iterable iterateNames() { - return new SingleIterable(getTarget()); + return PyUtil.flattenedParens(getTarget()); } public PyElement getElementNamed(final String the_name) { - PyElement target = getTarget(); - return ((target != null) && the_name.equals(target.getName()))? target : null; + return IterHelper.findName(iterateNames(), the_name); } public boolean mustResolveOutside() { diff --git a/python/testData/resolve/TupleInExcept.py b/python/testData/resolve/TupleInExcept.py new file mode 100644 index 000000000000..1ebd91de1cde --- /dev/null +++ b/python/testData/resolve/TupleInExcept.py @@ -0,0 +1,7 @@ +import errno +try: + f = open('myfile.txt') + s = f.readline() + i = int(s.strip()) +except IOError as (errno, strerror): + print "I/O error({0}): {1}".format(errno, strerror) diff --git a/python/testSrc/com/jetbrains/python/PyResolveTest.java b/python/testSrc/com/jetbrains/python/PyResolveTest.java index 8ec83a77600d..f77e879d6bcb 100644 --- a/python/testSrc/com/jetbrains/python/PyResolveTest.java +++ b/python/testSrc/com/jetbrains/python/PyResolveTest.java @@ -182,6 +182,12 @@ public class PyResolveTest extends PyResolveTestCase { assertTrue(targetElement.getParent() instanceof PyWithStatement); } + public void testTupleInExcept() throws Exception { + PsiElement targetElement = resolve(); + assertTrue(targetElement instanceof PyTargetExpression); + assertTrue(PsiTreeUtil.getParentOfType(targetElement, PyExceptPart.class) != null); + } + @Override protected String getTestDataPath() {