Returns a custom human-readable summary of obj. Args: obj: the value to describe. blacklist: same as blacklist in get_ignore_reason. leaves_only: boolean flag used when calling describe recursively. Useful for summarizing collections.
(obj, blacklist, leaves_only=False)
| 708 | # a human-readable representation, so you may freely modify it to suit your |
| 709 | # needs. |
| 710 | def describe(obj, blacklist, leaves_only=False): |
| 711 | """Returns a custom human-readable summary of obj. |
| 712 | |
| 713 | Args: |
| 714 | obj: the value to describe. |
| 715 | blacklist: same as blacklist in get_ignore_reason. |
| 716 | leaves_only: boolean flag used when calling describe recursively. Useful |
| 717 | for summarizing collections. |
| 718 | """ |
| 719 | if get_ignore_reason(obj, blacklist): |
| 720 | return "{}{}".format(get_ignore_reason(obj, blacklist), type(obj)) |
| 721 | if tf_inspect.isframe(obj): |
| 722 | return "frame: {}".format(tf_inspect.getframeinfo(obj)) |
| 723 | elif tf_inspect.ismodule(obj): |
| 724 | return "module: {}".format(obj.__name__) |
| 725 | else: |
| 726 | if leaves_only: |
| 727 | return "{}, {}".format(type(obj), id(obj)) |
| 728 | elif isinstance(obj, list): |
| 729 | return "list({}): {}".format( |
| 730 | id(obj), [describe(e, blacklist, leaves_only=True) for e in obj]) |
| 731 | elif isinstance(obj, tuple): |
| 732 | return "tuple({}): {}".format( |
| 733 | id(obj), [describe(e, blacklist, leaves_only=True) for e in obj]) |
| 734 | elif isinstance(obj, dict): |
| 735 | return "dict({}): {} keys".format(id(obj), len(obj.keys())) |
| 736 | elif tf_inspect.isfunction(obj): |
| 737 | return "function({}) {}; globals ID: {}".format( |
| 738 | id(obj), obj.__name__, id(obj.__globals__)) |
| 739 | else: |
| 740 | return "{}, {}".format(type(obj), id(obj)) |
| 741 | |
| 742 | def build_ref_graph(obj, graph, reprs, blacklist): |
| 743 | """Builds a reference graph as <referrer> -> <list of refferents>. |
no test coverage detected