ZODB provides a PersistentList and a PersistentMapping, but I'd like a PersistentSet. I wrote a quick class that mirrors the ancient PersistentList from ZODB 2. Because there's no UserSet in Python, I had to extend from the C-based built-in set.
class PersistentSet(UserSet, Persistent):
def __iand__(self, other):
set.__iand__(other)
self._p_changed = 1
...
...
...
def symmetric_difference_update(self, other):
set.symmetric_difference_update(other)
self._p_changed = 1
The code produced a "multiple bases have instance lay-out conflict" error. I tried creating a UserSet wrapper around set, but that didn't solve the problem either.
class UserSet(set):
def __init__(self):
self.value = set
def __getattribute__(self, name):
return self.value.__getattribute__(name
Finally, I imported sets.Set (superseded by the built-in set), but that seems to be implemented in C, too. I didn't find any set implementations on PyPI so I'm at a dead end now.
What are my options? I may have to implement a set from scratch or use UserDict and throw away all the values.