mgedmin / objgraph

Visually explore Python object graphs
http://mg.pov.lt/objgraph/
MIT License
753 stars 72 forks source link

objgraph should not merge distinct classes with same name #4

Closed mgedmin closed 10 years ago

mgedmin commented 10 years ago

Forwarded from LaunchPad #1183768:

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 }

mgedmin commented 10 years ago

Hm. I see people out there actually use the typestats() function. I'd hate to make a backwards-incompatible change and break their code.

How about this: typestats() gets a new argument, shortnames=True. Functions wrapping typestats(), like show_growth, get the same argument. Then perhaps in objgraph 2.0 I break backwards-compatibility by switching the default value to False.

mgedmin commented 10 years ago

Here's a list of all the APIs that should be able to distinguish foo.A from bar.A

I'm thinking for count()/by_type() I could check if the argument contains a '.', can compare the fully-qualified typename; if it doesn't, I use the current logic of using type(o).__name__.

I wonder if I can write a custom class with name that contains a dot. Oh well, evil people who do that can use by_type('module.Evil.Class').

I wonder if Python 3 __qualname__ is relevant here.

mgedmin commented 10 years ago

I'm pushing my WIP to the long-typenames branch.

I will probably rebase it interactively a few times before merging.

mgedmin commented 10 years ago

I merged the branch to master and deleted it.