from typing import Any
import inspect
import warnings


def _safe_getdoc(obj: Any) -> str:
    """Like `inspect.getdoc()`, but never raises. Always returns a stripped string."""
    try:
        doc = inspect.getdoc(obj) or ""
    except Exception as e:
        warnings.warn(
            f"inspect.getdoc({obj!r}) raised an exception: {e}",
            RuntimeWarning,
        )
        return ""
    else:
        return doc.strip()