Should not merge objects with same type name into one statistics entry in typestats

Bug #1183768 reported by Kevin Xiao
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
objgraph
Fix Committed
Undecided
Unassigned

Bug Description

Classes in different may have same class name, like

module.a.A
module.b.A

But `typestats` merges these objects into one entry key `"A"`, making the result of `show_growth` confusing.

I think it's better to use the full qualified name of a class as key is better,
{
"module.a.A": 12,
"module.b.A": 3
}

Revision history for this message
Wichert Akkerman (wichert) wrote :

I ran into this as well. I modified my copy of objgraph to always use a small utility function to build the dotted name for a type:

def _typename(o):
    t = type(o)
    m = getattr(t, '__module__' '')
    if m:
        return '%s.%s' % (m, t.__name__)
    else:
        return t.__name__

And modified all code using type(o).__name__ to use _typename(o) instead.

Revision history for this message
Marius Gedminas (mgedmin) wrote :

Apologies for not noticing this sooner. (Launchpad didn't send me any email, possibly because I didn't configure the project page correctly.)

The suggestion makes sense, I'll make it so.

Revision history for this message
Marius Gedminas (mgedmin) wrote :

Can we please continue this on GitHub? Their bugtracker is nicer.

https://github.com/mgedmin/objgraph/issues/4

Revision history for this message
Marius Gedminas (mgedmin) wrote :

Fixed in master, by adding an optional shortnames argument, with default value that keeps backwards-compatibility.

You can now use objgraph.show_growth(shortnames=False) to see fully-qualified type names.

Changed in objgraph:
status: New → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.