def __hook_module(self, module: typing.Any) -> None: class _Module(module.__class__, _HookedModule): pass module.__class__ = _Module return module
def as_string( val: t.Any) -> t.Union[t.Dict[str, t.Any], t.List[t.Any], str, UnRepr]: if isinstance(val, dict): return {k: as_string(v) for k, v in val.items()} elif isinstance(val, (tuple, list)): return val.__class__([as_string(v) for v in val]) elif hasattr(val, "emit"): return UnRepr(val) elif callable(val) and hasattr(val, "__name__"): return val.__name__ # todo: fullname else: return repr(val)
def as_string(val: t.Any) -> t.Union[t.Dict[str, t.Any], t.List[t.Any], str, UnRepr]: if isinstance(val, dict): return {k: as_string(v) for k, v in val.items()} elif isinstance(val, (tuple, list)): return val.__class__([as_string(v) for v in val]) elif getattr(val, "__module__", None) == "prestring.utils": return val elif isinstance(val, _LazyFormatRepr): # xxx: return str(val) elif hasattr(val, "emit"): return UnRepr(val) elif callable(val) and hasattr(val, "__name__"): return val.__name__ # todo: fullname else: return repr(val)