PyClass () { final PyTargetExpressionStub stub = getStub(); if (stub != null) { final StubElement parentStub = stub.getParentStub(); if (parentStub instanceof PyClassStub) { return ((PyClassStub)parentStub).getPsi(); } if (parentStub instanceof PyFunctionStub) { final StubElement functionParent = parentStub.getParentStub(); if (functionParent instanceof PyClassStub) { return ((PyClassStub)functionParent).getPsi(); } } return null; } final PsiElement parent = PsiTreeUtil.getParentOfType(this, PyFunction.class, PyClass.class); if (parent instanceof PyClass) { return (PyClass)parent; } if (parent instanceof PyFunction) { return ((PyFunction)parent).getContainingClass(); } return null; }