Repository: Textualize/rich
File: rich/console.py (Python)

Code before:

            renderables = [
                self._log_render(
                    self,
                    renderables,
                    log_time=self.get_datetime(),
                    path=path,
                    line_no=line_no,
                    link_path=link_path,
                )
            ]
            for hook in render_hooks:
                renderables = hook.process_renderables(renderables)
            new_segments: List[Segment] = []
            extend = new_segments.extend
            render = self.render
            render_options = self.options
            for renderable in renderables:
                extend(render(renderable, render_options))
            buffer_extend = self._buffer.extend
            for line in Segment.split_and_crop_lines(
                new_segments, self.width, pad=False
            ):
                buffer_extend(line)

    def _check_and_render_buffer(self) -> None:
        """Check if the buffer may be rendered. Render it if it can."""
        if self.quiet:
            del self._buffer[:]
            return
        with self._lock:
            if self._buffer_index == 0:

                if self.record:
                    with self._record_buffer_lock:
                        self._record_buffer.extend(self._buffer[:])

                if self.is_jupyter:  # pragma: no cover
                    from .jupyter import display

                    display(self._buffer, self._render_buffer(self._buffer[:]))
                    del self._buffer[:]
                else:
                    if WINDOWS:
                        try:
                            file_no = self.file.fileno()
                            stdout_num = sys.stdout.fileno()
                            stderr_num = sys.stderr.fileno()
                        except (ValueError, io.UnsupportedOperation):
                            file_no = -1
                            stdout_num = 1

Review comment (suggestion):
I know the name is more apt, and since this is private it is *probably* safe to change. But at this stage I fear it might break somebody's code, and it probably isn't worth it. Would you mind reverting the name change.

The docstring is of course good. If anything you could elaborate on it for future generations, i.e. more detail in what a check does and what causes a render.

Code after:
            link_path = None if filename.startswith("<") else os.path.abspath(filename)
            path = filename.rpartition(os.sep)[-1]
            if log_locals:
                locals_map = {
                    key: value
                    for key, value in locals.items()
                    if not key.startswith("__")
                }
                renderables.append(render_scope(locals_map, title="[i]locals"))

            renderables = [
                self._log_render(
                    self,
                    renderables,
                    log_time=self.get_datetime(),
                    path=path,
                    line_no=line_no,
                    link_path=link_path,
                )
            ]
            for hook in render_hooks:
                renderables = hook.process_renderables(renderables)
            new_segments: List[Segment] = []
            extend = new_segments.extend
            render = self.render
            render_options = self.options
            for renderable in renderables:
                extend(render(renderable, render_options))
            buffer_extend = self._buffer.extend
            for line in Segment.split_and_crop_lines(
                new_segments, self.width, pad=False
            ):
                buffer_extend(line)

    def _check_buffer(self) -> None:
        """Check if the buffer may be rendered. Render it if it can (e.g. Console.quiet is False)
        Rendering is supported on Windows, Unix and Jupyter environments. For
        legacy Windows consoles, the win32 API is called directly.
        This method will also record what it renders if recording is enabled via Console.record.
        """
        if self.quiet:
            del self._buffer[:]
            return
        with self._lock:
            if self._buffer_index == 0:

                if self.record:
                    with self._record_buffer_lock:
                        self._record_buffer.extend(self._buffer[:])

                if self.is_jupyter:  # pragma: no cover