def meta_repr(obj: object, key: object) -> Callable[[], str]:
            "Abbreviate meta text, make sure it fits on one line."
            cached_result: str | None = None

            # We return a function, so that it gets computed when it's needed.
            # When there are many completions, that improves the performance
            # quite a bit (for the multi-column completion menu, we only need
            # to display one meta text).
            # Note that we also do the lookup itself in here (`obj[key]`),
            # because this part can also be slow for some mapping
            # implementations.
            def get_value_repr() -> str:
                nonlocal cached_result
                if cached_result is not None:
                    return cached_result

                try:
                    value = obj[key]  # type: ignore

                    text = self._do_repr(value)
                except BaseException:
                    return "-"

                # Take first line, if multiple lines.
                if "\n" in text:
                    text = text.split("\n", 1)[0] + "..."

                cached_result = text
                return text

            return get_value_repr
Abbreviate meta text, make sure it fits on one line.
src/ptpython/completer.py