pyinfra/pyinfra/server/debugging.py
2022-05-16 14:58:19 +02:00

28 lines
609 B
Python

from itertools import tee
from typing import Iterable
def inspect(prefix="inspect", embed=False):
"""Can be used to inspect compositions of generator functions by placing inbetween two functions."""
def inner(x):
if isinstance(x, Iterable) and not isinstance(x, dict) and not isinstance(x, tuple):
x, y = tee(x)
y = list(y)
else:
y = x
l = f" {len(y)} items" if isinstance(y, list) else ""
print(f"{prefix}{l}:", y)
if embed:
import IPython
IPython.embed()
return x
return inner