I am creating a descriptor, and I want to create a list inside it that holds references to all objects implementing it, it is supposed to be some kind of a shortcut where I
If that's all your descriptor do, it's a bit of an abuse of the descriptor protocol. Just overriding your class __new__
or __init__
would be simpler:
class Foo(object):
_instances = []
def __new__(cls, *args, **kw):
instance = object.__new__(cls)
cls._instances.append(instance)
return instance
@classmethod
def get_instances(cls):
return self._instances