diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-09-05 14:28:10 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-09-05 14:28:10 (GMT) |
commit | 6db9e88effca95d6d48db243a05169b3ed79bc2d (patch) | |
tree | 898d65eb7459d06b012738206f3ec3d18163d413 | |
parent | 930c3c9e43dee8ad65f33d167b0c511cd22f6334 (diff) | |
download | cpython-6db9e88effca95d6d48db243a05169b3ed79bc2d.zip cpython-6db9e88effca95d6d48db243a05169b3ed79bc2d.tar.gz cpython-6db9e88effca95d6d48db243a05169b3ed79bc2d.tar.bz2 |
Issue #18830: inspect.getclasstree() no more produces duplicated entries even
when input list contains duplicates.
-rw-r--r-- | Lib/inspect.py | 3 | ||||
-rw-r--r-- | Lib/test/inspect_fodder.py | 2 | ||||
-rw-r--r-- | Lib/test/test_inspect.py | 19 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
4 files changed, 24 insertions, 3 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index c2a32fe..9336943 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -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) diff --git a/Lib/test/inspect_fodder.py b/Lib/test/inspect_fodder.py index afde2e2..5c87ae6 100644 --- a/Lib/test/inspect_fodder.py +++ b/Lib/test/inspect_fodder.py @@ -49,6 +49,8 @@ class StupidGit: class MalodorousPervert(StupidGit): pass +Tit = MalodorousPervert + class ParrotDroppings: pass diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 04dcfe9..4130cd0 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -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, ()), @@ -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). |