]> granicus.if.org Git - python/commitdiff
Issue #18830: inspect.getclasstree() no more produces duplicated entries even
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 5 Sep 2013 14:28:10 +0000 (17:28 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 5 Sep 2013 14:28:10 +0000 (17:28 +0300)
when input list contains duplicates.

Lib/inspect.py
Lib/test/inspect_fodder.py
Lib/test/test_inspect.py
Misc/NEWS

index c2a32fee246a6f91e83022cb932f7d3f29a32735..933694394dd1fe3880c998147b448da4d8420733 100644 (file)
@@ -728,7 +728,8 @@ def getclasstree(classes, unique=0):
             for parent in c.__bases__:
                 if not parent in children:
                     children[parent] = []
-                children[parent].append(c)
+                if c not in children[parent]:
+                    children[parent].append(c)
                 if unique and parent in classes: break
         elif c not in roots:
             roots.append(c)
index afde2e2514b19fb55f11329cec2bf503c9391445..5c87ae6f828be8ddb089c64bb49b27eedf092952 100644 (file)
@@ -49,6 +49,8 @@ class StupidGit:
 class MalodorousPervert(StupidGit):
     pass
 
+Tit = MalodorousPervert
+
 class ParrotDroppings:
     pass
 
index 04dcfe992a491d79c1c250d0d1108ac378813b72..4130cd0b502bcc92443d817aea104598dfa1ba89 100644 (file)
@@ -220,8 +220,23 @@ class TestRetrievingSourceCode(GetSourceBase):
                          [('FesteringGob', mod.FesteringGob),
                           ('MalodorousPervert', mod.MalodorousPervert),
                           ('ParrotDroppings', mod.ParrotDroppings),
-                          ('StupidGit', mod.StupidGit)])
-        tree = inspect.getclasstree([cls[1] for cls in classes], 1)
+                          ('StupidGit', mod.StupidGit),
+                          ('Tit', mod.MalodorousPervert),
+                         ])
+        tree = inspect.getclasstree([cls[1] for cls in classes])
+        self.assertEqual(tree,
+                         [(mod.ParrotDroppings, ()),
+                          [(mod.FesteringGob, (mod.MalodorousPervert,
+                                                  mod.ParrotDroppings))
+                           ],
+                          (mod.StupidGit, ()),
+                          [(mod.MalodorousPervert, (mod.StupidGit,)),
+                           [(mod.FesteringGob, (mod.MalodorousPervert,
+                                                   mod.ParrotDroppings))
+                            ]
+                           ]
+                          ])
+        tree = inspect.getclasstree([cls[1] for cls in classes], True)
         self.assertEqual(tree,
                          [(mod.ParrotDroppings, ()),
                           (mod.StupidGit, ()),
index 14201ca486983cb5fe0b71bda3394f68cc3ed0c9..3bbced36d0faec9c624fba46037048ab61ae8252 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -32,6 +32,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #18830: inspect.getclasstree() no more produces duplicated entries even
+  when input list contains duplicates.
+
 - Issue #18909: Fix _tkinter.tkapp.interpaddr() on Windows 64-bit, don't cast
   64-bit pointer to long (32 bits).