mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
support tuples in 'except' part of try ... except (PY-293)
This commit is contained in:
@@ -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];
|
||||
|
||||
@@ -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 <T extends PyElement> List<T> flattenedParens(T[] targets) {
|
||||
public static <T extends PyElement> List<T> flattenedParens(T... targets) {
|
||||
return _unfoldParenExprs(targets, new ArrayList<T>(targets.length));
|
||||
}
|
||||
|
||||
|
||||
@@ -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<PyElement> iterateNames() {
|
||||
return new SingleIterable<PyElement>(getTarget());
|
||||
return PyUtil.<PyElement>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() {
|
||||
|
||||
@@ -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(e<ref>rrno, strerror)
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user