Closed puiseux closed 1 year ago
Well, it looks like a bug in sortedset.py
:
SortedSet.union()
calls SortedSet.__class__(x,k=self._key)
with two arguments. But this __class__()
property is defined in object.__class__(x)
from builtins.py
and requires only one unique argument.
So I just override SortedSet.union()
(locally) like this :
def union(self, *iterables):
# return self.__class__(chain(iter(self), *iterables), key=self._key)
return self.__class__(chain(iter(self), *iterables))
Like this, it looks OK. But it's an ugly solution !
Well, a better solution is not to override SortedSet.union()
, but to declare Index.__init__(iterable=None, key=None)
with **key**
argument.
The init method of SortedSet adds an optional key parameter. Your subclass version is taking that away which is going to cause issues. See https://stackoverflow.com/questions/6034662/python-method-overriding-does-signature-matter for a description of the issue.
Hello, I create a
class Index
that inherits fromSortedSet
. ButUnion
does not work as expected. Here is the piece of code :and here is the result :
Notice that if I replace
Index
withSortedSet
, it works perfectly :