Merge branch 'python-fixes'

This commit is contained in:
Andrey Vlasovskikh
2015-02-17 17:42:24 +03:00
3 changed files with 30 additions and 5 deletions
@@ -100,20 +100,29 @@ public class ScopeUtil {
if (decoratorAncestor != null && !isAncestor(decoratorAncestor, firstOwner, true)) {
return nextOwner;
}
// References in default values of parameters are resolved outside of the function (if the lambda is not inside the default value)
final PyParameter parameterAncestor = getParentOfType(element, PyParameter.class);
// References in default values or in annotations of parameters are resolved outside of the function (if the lambda is not inside the
// default value)
final PyNamedParameter parameterAncestor = getParentOfType(element, PyNamedParameter.class);
if (parameterAncestor != null && !isAncestor(parameterAncestor, firstOwner, true)) {
final PyExpression defaultValue = parameterAncestor.getDefaultValue();
if (element != null && isAncestor(defaultValue, element, false)) {
final PyAnnotation annotation = parameterAncestor.getAnnotation();
if (isAncestor(defaultValue, element, false) || isAncestor(annotation, element, false)) {
return nextOwner;
}
}
// Superclasses are resolved outside of the class
final PyClass containingClass = getParentOfType(element, PyClass.class);
if (containingClass != null && element != null &&
isAncestor(containingClass.getSuperClassExpressionList(), element, false)) {
if (containingClass != null && isAncestor(containingClass.getSuperClassExpressionList(), element, false)) {
return nextOwner;
}
// Function return annotations are resolved outside of the function
if (firstOwner instanceof PyFunction) {
final PyFunction function = (PyFunction)firstOwner;
final PyAnnotation annotation = function.getAnnotation();
if (isAncestor(annotation, element, false)) {
return nextOwner;
}
}
return firstOwner;
}
@@ -0,0 +1,11 @@
class B:
class C:
pass
class Return:
pass
value = 10
def foo(self, x: C, y: value) -> Return:
pass
@@ -116,4 +116,9 @@ public class Py3UnresolvedReferencesInspectionTest extends PyTestCase {
public void testNotImportedSubmodulesOfNamespacePackage() {
doMultiFileTest("main.py");
}
// PY-15017
public void testClassLevelReferenceInMethodAnnotation() {
doTest();
}
}