]> 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:14:32 +0000 (17:14 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 5 Sep 2013 14:14:32 +0000 (17:14 +0300)
when input list contains duplicates.

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

index c7e7ef56dd8a53613f1a0714fbf55cadfa505b6e..9337bd590b90a194e84aab36b423ce2cb090b705 100644 (file)
@@ -753,7 +753,8 @@ def getclasstree(classes, unique=False):
             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 ec96eb7e435efe52071ce56ff9b892eb18ab77a4..0c1d8103e9d0cb0d97099b05a08ae64fe5d003b2 100644 (file)
@@ -49,6 +49,8 @@ class StupidGit:
 class MalodorousPervert(StupidGit):
     pass
 
+Tit = MalodorousPervert
+
 class ParrotDroppings:
     pass
 
index 9f5e93b0c7fb4663847a970f360743d2149260a3..5cbec9bb17b4593cb04720b4041f7cf347ae5a46 100644 (file)
@@ -224,8 +224,25 @@ 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,
+                         [(object, ()),
+                          [(mod.ParrotDroppings, (object,)),
+                           [(mod.FesteringGob, (mod.MalodorousPervert,
+                                                   mod.ParrotDroppings))
+                            ],
+                           (mod.StupidGit, (object,)),
+                           [(mod.MalodorousPervert, (mod.StupidGit,)),
+                            [(mod.FesteringGob, (mod.MalodorousPervert,
+                                                    mod.ParrotDroppings))
+                             ]
+                            ]
+                           ]
+                          ])
+        tree = inspect.getclasstree([cls[1] for cls in classes], True)
         self.assertEqual(tree,
                          [(object, ()),
                           [(mod.ParrotDroppings, (object,)),
index c7dbe2993a8946456b1dcf9115fc2f279d3b0bdd..66fc600f294ca3de4c83b4b1965ee5219ffff41f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -66,6 +66,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).