python: optimize PythonCollector.collect

This commit is contained in:
Ran Benita 2020-04-30 20:13:26 +03:00
parent b90f34569f
commit 89eee90b5f
1 changed files with 5 additions and 3 deletions

View File

@ -365,15 +365,17 @@ class PyCollector(PyobjMixin, nodes.Collector):
# NB. we avoid random getattrs and peek in the __dict__ instead
# (XXX originally introduced from a PyPy need, still true?)
dicts = [getattr(self.obj, "__dict__", {})]
for basecls in inspect.getmro(self.obj.__class__):
for basecls in self.obj.__class__.__mro__:
dicts.append(basecls.__dict__)
seen = {}
seen = set()
values = []
for dic in dicts:
# Note: seems like the dict can change during iteration -
# be careful not to remove the list() without consideration.
for name, obj in list(dic.items()):
if name in seen:
continue
seen[name] = True
seen.add(name)
res = self._makeitem(name, obj)
if res is None:
continue