private static @Nullable PyFile getPyFile(@NotNull Project project, @NotNull VirtualFile virtualFile) {
    VirtualFile targetFile = Arrays.stream(FileEditorManager.getInstance(project).getAllEditors(virtualFile))
      .map(editor -> editor.getFile())
      .filter(file -> file instanceof BackedVirtualFile)
      .findFirst()
      .orElse(virtualFile);
    
    return (PyFile)ContainerUtil.find(
      Objects.requireNonNull(PsiManager.getInstance(project).findFile(targetFile))
        .getViewProvider()
        .getAllFiles(), file -> file instanceof PyFile);
  }
private static @Nullable PyFile getPyFile(@NotNull Project project, @NotNull VirtualFile virtualFile)