ScopeOwner (PyTargetExpression local) { ScopeOwner context = PsiTreeUtil.getParentOfType(local, PyFunction.class); if (context == null) { context = PsiTreeUtil.getParentOfType(local, PyClass.class); } if (context == null) { context = (PyFile)local.getContainingFile(); } return context; }