Repository: Lightning-AI/pytorch-lightning
File: src/lightning/pytorch/callbacks/progress/rich_progress.py (Python)

Code before:
    @override
    def disable(self) -> None:
        self._enabled = False

    @override
    def enable(self) -> None:
        self._enabled = True

    def _init_progress(self, trainer: "pl.Trainer") -> None:
        if self.is_enabled and (self.progress is None or self._progress_stopped):
            self._reset_progress_bar_ids()
            reconfigure(**self._console_kwargs)
            self._console = get_console()

            # Compatibility shim for Rich >= 14.1.0:
            # In recent Rich releases, the internal `_live` variable was replaced with `_live_stack` (a list)
            # to support nested Live displays. This broke our original call to `clear_live()`,
            # because it now only pops one Live instance instead of clearing them all.
            # We check for `_live_stack` and clear it manually for compatibility across
            # both old and new Rich versions.
            if hasattr(self._console, "_live_stack"):
                if len(self._console._live_stack) > 0:
                    self._console.clear_live()
            else:
                self._console.clear_live()

            self._metric_component = MetricsTextColumn(
                trainer,
                self.theme.metrics,
                self.theme.metrics_text_delimiter,
                self.theme.metrics_format,
            )
            self.progress = CustomProgress(
                *self.configure_columns(trainer),
                self._metric_component,
                auto_refresh=False,
                disable=self.is_disabled,
                console=self._console,
            )
            self.progress.start()
            # progress has started
            self._progress_stopped = False

    def refresh(self) -> None:
        if self.progress:
            self.progress.refresh()

    @override
    def on_train_start(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule") -> None:
        self._init_progress(trainer)


Review comment (suggestion):
Great find @deependujha

Just a note: I’ve noticed in PyTorch Lightning that when there are breaking changes, constants are often introduced with pinned versions.
For example:

https://github.com/Lightning-AI/pytorch-lightning/blob/5d89996472994be708eda253a30fa1b79a31f23c/src/lightning/fabric/strategies/deepspeed.py#L48-L51

https://github.com/Lightning-AI/pytorch-lightning/blob/5d89996472994be708eda253a30fa1b79a31f23c/src/lightning/fabric/strategies/deepspeed.py#L505-L510

Not sure if this applies here, but might be worth checking.

cc: @Borda 

Code after:
    @override
    def disable(self) -> None:
        self._enabled = False

    @override
    def enable(self) -> None:
        self._enabled = True

    def _init_progress(self, trainer: "pl.Trainer") -> None:
        if self.is_enabled and (self.progress is None or self._progress_stopped):
            self._reset_progress_bar_ids()
            reconfigure(**self._console_kwargs)
            self._console = get_console()

            # Compatibility shim for Rich >= 14.1.0:
            if hasattr(self._console, "_live_stack"):
                # In recent Rich releases, the internal `_live` variable was replaced with `_live_stack` (a list)
                # to support nested Live displays. This broke our original call to `clear_live()`,
                # because it now only pops one Live instance instead of clearing them all.
                # We check for `_live_stack` and clear it manually for compatibility across
                # both old and new Rich versions.
                if len(self._console._live_stack) > 0:
                    self._console.clear_live()
            else:
                self._console.clear_live()

            self._metric_component = MetricsTextColumn(
                trainer,
                self.theme.metrics,
                self.theme.metrics_text_delimiter,
                self.theme.metrics_format,
            )
            self.progress = CustomProgress(
                *self.configure_columns(trainer),
                self._metric_component,
                auto_refresh=False,
                disable=self.is_disabled,
                console=self._console,
            )
            self.progress.start()
            # progress has started
            self._progress_stopped = False

    def refresh(self) -> None:
        if self.progress:
            self.progress.refresh()

    @override
    def on_train_start(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule") -> None:
        self._init_progress(trainer)