Builds a reference graph as -> . Args: obj: The object to start from. The graph will be built by recursively adding its referrers. graph: Dict holding the graph to be built. To avoid creating extra references, the graph holds object IDs
(obj, graph, reprs, blacklist)
| 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>. |
| 744 | |
| 745 | Args: |
| 746 | obj: The object to start from. The graph will be built by recursively |
| 747 | adding its referrers. |
| 748 | graph: Dict holding the graph to be built. To avoid creating extra |
| 749 | references, the graph holds object IDs rather than actual objects. |
| 750 | reprs: Auxiliary structure that maps object IDs to their human-readable |
| 751 | description. |
| 752 | blacklist: List of objects to ignore. |
| 753 | """ |
| 754 | referrers = gc.get_referrers(obj) |
| 755 | blacklist = blacklist + (referrers,) |
| 756 | |
| 757 | obj_id = id(obj) |
| 758 | for r in referrers: |
| 759 | if get_ignore_reason(r, blacklist) is None: |
| 760 | r_id = id(r) |
| 761 | if r_id not in graph: |
| 762 | graph[r_id] = [] |
| 763 | if obj_id not in graph[r_id]: |
| 764 | graph[r_id].append(obj_id) |
| 765 | build_ref_graph(r, graph, reprs, blacklist) |
| 766 | reprs[r_id] = describe(r, blacklist) |
| 767 | |
| 768 | def find_cycle(el, graph, reprs, path): |
| 769 | """Finds and prints a single cycle in the dependency graph.""" |
no test coverage detected