PyClass (@Nullable PsiElement element) { for (ScopeOwner owner = ScopeUtil.getScopeOwner(element); owner != null; owner = ScopeUtil.getScopeOwner(owner)) { if (owner instanceof PyClass) { return (PyClass)owner; } } return null; }