@Nullable
  public static AstScopeOwner getScopeOwner(@Nullable final PsiElement element) {
    if (element == null) {
      return null;
    }
    if (element instanceof PyAstExpressionCodeFragment) {
      final PsiElement context = element.getContext();
      return context instanceof AstScopeOwner ? (AstScopeOwner)context : getScopeOwner(context);
    }
    if (element instanceof StubBasedPsiElement) {
      final StubElement stub = ((StubBasedPsiElement<?>)element).getStub();
      if (stub != null) {
        StubElement parentStub = stub.getParentStub();
        while (parentStub != null) {
          final PsiElement parent = parentStub.getPsi();
          if (parent instanceof AstScopeOwner) {
            return (AstScopeOwner)parent;
          }
          parentStub = parentStub.getParentStub();
        }
        return null;
      }
    }
    return CachedValuesManager.getCachedValue(element, () -> CachedValueProvider.Result
      .create(calculateScopeOwnerByAST(element), PsiModificationTracker.MODIFICATION_COUNT));
  }
@Nullable
  public static AstScopeOwner getScopeOwner(@Nullable final PsiElement element)