diff --git a/py/_com.py b/py/_com.py index c9736b388..2c26338fc 100644 --- a/py/_com.py +++ b/py/_com.py @@ -120,7 +120,7 @@ class PyPlugins: def isregistered(self, plugin): return plugin in self._plugins - def listattr(self, attrname, plugins=None, extra=()): + def listattr(self, attrname, plugins=None, extra=(), reverse=False): l = [] if plugins is None: plugins = self._plugins @@ -131,6 +131,8 @@ class PyPlugins: l.append(getattr(plugin, attrname)) except AttributeError: continue + if reverse: + l.reverse() return l def call_each(self, methname, *args, **kwargs): diff --git a/py/misc/testing/test_com.py b/py/misc/testing/test_com.py index 84a2e6b7c..1aa8f1d73 100644 --- a/py/misc/testing/test_com.py +++ b/py/misc/testing/test_com.py @@ -154,14 +154,18 @@ class TestPyPlugins: def test_listattr(self): plugins = PyPlugins() class api1: - x = 42 - class api2: x = 41 + class api2: + x = 42 + class api3: + x = 43 plugins.register(api1()) plugins.register(api2()) + plugins.register(api3()) l = list(plugins.listattr('x')) - l.sort() - assert l == [41, 42] + assert l == [41, 42, 43] + l = list(plugins.listattr('x', reverse=True)) + assert l == [43, 42, 41] def test_notify_anonymous_ordered(self): plugins = PyPlugins()