| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | from collections.abc import Callable |
| 5 | from typing import Any |
| 6 | |
| 7 | |
| 8 | class lazy: |
| 9 | """Wrap a zero-argument callable evaluated only during log formatting.""" |
| 10 | |
| 11 | __slots__ = ("_factory",) |
| 12 | |
| 13 | def __init__(self, factory: Callable[[], Any]) -> None: |
| 14 | self._factory = factory |
| 15 | |
| 16 | def __str__(self) -> str: |
| 17 | return str(self._factory()) |
| 18 | |
| 19 | def __repr__(self) -> str: |
| 20 | return str(self) |