rich/examples/tqdm_hidden_lib.py
K2 adcb5c748c Add tqdm compatibility shim with Rich progress backend
Implements a runtime adapter that replaces tqdm imports with Rich's
progress bars via install_tqdm(). The shim preserves common tqdm APIs
(iteration, len(), postfix, write, wrapattr) while routing rendering
through rich.progress.Progress.

Features:
- Opt-in monkeypatching of tqdm/trange and notebook variants
- Shared global Progress instance for performance
- Render throttling via mininterval/miniters/maxinterval
- Simplified text backend for file outputs (partial mode)
- Postfix value caching to avoid redundant formatting

Includes runnable examples demonstrating basic replacement and
aggressive reference overwriting, plus comprehensive unit tests
covering adapter installation, throttling, and postfix handling.

Updates README and contributor list.
2025-12-05 07:41:51 -05:00

15 lines
327 B
Python

"""Simulated third-party module that hides a tqdm reference internally.
Imported by tqdm_adapter_hidden.py to demonstrate aggressive replacement.
"""
import time
import tqdm as _tqdm
_hidden_tqdm = _tqdm.tqdm
def run_hidden_loop() -> None:
for _ in _hidden_tqdm(range(5), desc="hidden-lib"):
time.sleep(0.05)