summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Lib/inspect.py3
-rw-r--r--Lib/test/inspect_fodder.py2
-rw-r--r--Lib/test/test_inspect.py21
-rw-r--r--Misc/NEWS3
4 files changed, 26 insertions, 3 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index c7e7ef56dd..9337bd590b 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -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)
diff --git a/Lib/test/inspect_fodder.py b/Lib/test/inspect_fodder.py
index ec96eb7e43..0c1d8103e9 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 9f5e93b0c7..5cbec9bb17 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -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,)),
diff --git a/Misc/NEWS b/Misc/NEWS
index c7dbe2993a..66fc600f29 100644
--- 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).