-
-
Notifications
You must be signed in to change notification settings - Fork 72
correct labels for dicts #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1000,7 +1000,11 @@ def _show_graph(objs, edge_func, swap_source_target, | |
| continue | ||
| if cull_func is not None and cull_func(target): | ||
| continue | ||
| neighbours = edge_func(target) | ||
| edges = edge_func(target) | ||
| # `neighbours` is `edges` without duplicates, and `counts` is the count of duplicates | ||
| counts = collections.Counter(id(v) for v in edges) | ||
| neighbours = list({id(v): v for v in edges}.values()) | ||
| del edges | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So AFAIU
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need for a comment if we can add https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.unique_everseen
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather not; I like that objgraph is a single file library with no external dependencies I can copy over into any random location on my python path and start using immediately. |
||
| ignore.add(id(neighbours)) | ||
| n = 0 | ||
| skipped = 0 | ||
|
|
@@ -1016,9 +1020,13 @@ def _show_graph(objs, edge_func, swap_source_target, | |
| srcnode, tgtnode = target, source | ||
| else: | ||
| srcnode, tgtnode = source, target | ||
| elabel = _edge_label(srcnode, tgtnode, shortnames) | ||
| f.write(' %s -> %s%s;\n' % (_obj_node_id(srcnode), | ||
| _obj_node_id(tgtnode), elabel)) | ||
| for elabel, _ in itertools.zip_longest( | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't work on Python 2.7. I'd have to stop and think whether I want to drop Python 2.7 compatibility at this point. |
||
| _edge_labels(srcnode, tgtnode, shortnames), | ||
| range(counts[id(source)]), | ||
| fillvalue='', | ||
| ): | ||
graingert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| f.write(' %s -> %s%s;\n' % (_obj_node_id(srcnode), | ||
| _obj_node_id(tgtnode), elabel)) | ||
| if id(source) not in depth: | ||
| depth[id(source)] = tdepth + 1 | ||
| queue.append(source) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A couple of lines down from here there's a It probably doesn't matter,
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah I figured it wasn't worth it, could wrap this whole thing in a |
||
|
|
@@ -1208,43 +1216,43 @@ def _gradient(start_color, end_color, depth, max_depth): | |
| return h, s, v | ||
|
|
||
|
|
||
| def _edge_label(source, target, shortnames=True): | ||
| def _edge_labels(source, target, shortnames=True): | ||
| if (_isinstance(target, dict) | ||
| and target is getattr(source, '__dict__', None)): | ||
| return ' [label="__dict__",weight=10]' | ||
| yield ' [label="__dict__",weight=10]' | ||
| if _isinstance(source, types.FrameType): | ||
| if target is source.f_locals: | ||
| return ' [label="f_locals",weight=10]' | ||
| yield ' [label="f_locals",weight=10]' | ||
| if target is source.f_globals: | ||
| return ' [label="f_globals",weight=10]' | ||
| yield ' [label="f_globals",weight=10]' | ||
| if _isinstance(source, types.MethodType): | ||
| try: | ||
| if target is source.__self__: | ||
| return ' [label="__self__",weight=10]' | ||
| yield ' [label="__self__",weight=10]' | ||
| if target is source.__func__: | ||
| return ' [label="__func__",weight=10]' | ||
| yield ' [label="__func__",weight=10]' | ||
| except AttributeError: # pragma: nocover | ||
| # Python < 2.6 compatibility | ||
| if target is source.im_self: | ||
| return ' [label="im_self",weight=10]' | ||
| yield ' [label="im_self",weight=10]' | ||
| if target is source.im_func: | ||
| return ' [label="im_func",weight=10]' | ||
| yield ' [label="im_func",weight=10]' | ||
| if _isinstance(source, types.FunctionType): | ||
| for k in dir(source): | ||
| if target is getattr(source, k): | ||
| return ' [label="%s",weight=10]' % _quote(k) | ||
| yield ' [label="%s",weight=10]' % _quote(k) | ||
| if _isinstance(source, dict): | ||
| tn = _short_typename if shortnames else _long_typename | ||
| for k, v in iteritems(source): | ||
| if v is target: | ||
| if _isinstance(k, basestring) and _is_identifier(k): | ||
| return ' [label="%s",weight=2]' % _quote(k) | ||
| yield ' [label="%s",weight=2]' % _quote(k) | ||
| else: | ||
| if shortnames: | ||
| tn = _short_typename(k) | ||
| else: | ||
| tn = _long_typename(k) | ||
| return ' [label="%s"]' % _quote(tn + "\n" + _safe_repr(k)) | ||
| return '' | ||
| yield ' [label="%s"]' % _quote(tn(k) + "\n" + _safe_repr(k)) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for adding |
||
|
|
||
|
|
||
| def _edge_label(*args, **kwargs): | ||
| return next(_edge_labels(*args, **kwargs), '') | ||
|
|
||
|
|
||
| _is_identifier = re.compile('[a-zA-Z_][a-zA-Z_0-9]*$').match | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.