[Python-checkins] cpython (merge 3.3 -> default): Issue #18830: inspect.getclasstree() no more produces duplicated entries even

serhiy.storchaka python-checkins at python.org
Thu Sep 5 16:37:50 CEST 2013


http://hg.python.org/cpython/rev/86ab7b7c173e
changeset:   85541:86ab7b7c173e
parent:      85534:a62f59667c9e
parent:      85540:39d0dfa5808c
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Thu Sep 05 17:16:12 2013 +0300
summary:
  Issue #18830: inspect.getclasstree() no more produces duplicated entries even
when input list contains duplicates.

files:
  Lib/inspect.py             |   3 ++-
  Lib/test/inspect_fodder.py |   2 ++
  Lib/test/test_inspect.py   |  21 +++++++++++++++++++--
  Misc/NEWS                  |   3 +++
  4 files changed, 26 insertions(+), 3 deletions(-)


diff --git a/Lib/inspect.py b/Lib/inspect.py
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -789,7 +789,8 @@
             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)
diff --git a/Lib/test/inspect_fodder.py b/Lib/test/inspect_fodder.py
--- a/Lib/test/inspect_fodder.py
+++ b/Lib/test/inspect_fodder.py
@@ -49,6 +49,8 @@
 class MalodorousPervert(StupidGit):
     pass
 
+Tit = MalodorousPervert
+
 class ParrotDroppings:
     pass
 
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -225,8 +225,25 @@
                          [('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,)),
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -54,6 +54,9 @@
 Library
 -------
 
+- Issue #18830: inspect.getclasstree() no more produces duplicated entries even
+  when input list contains duplicates.
+
 - Issue #18878: sunau.open now supports the context manager protocol.  Based on
   patches by Claudiu Popa and R. David Murray.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list