You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My understanding is that SortedList.extend was removed because there was some sort of efficiency concern, and it was deemed preferable for people to use SortedList.update. Similarly, SortedList.append throws an error and it is preferable for people to use add.
I guess the reasoning here is that append and extend are not actually meaningful concepts to a SortedList (since "append" means "add to the end" not "add in sorted order).
However, throwing NotImpementedError breaks Liskov substitution for SortedList - it's not actually a MutableSequence, since a MutableSequence is guaranteed to have extend and append methods. This is a problem because code that uses type hinting to accept MutableSequence, or dispatches based on type is expecting to be able to use these methods.
I think it would be best to drop MutableSequence as a base class in favor of Sequence and make sure that these methods are actually not implemented (either using the __getattr__ trick used in SortedDict or just by dropping them entirely) so that isinstance checks will properly fail.
An alternative would be to accept a lesser Liskov substitution violation and make them aliases for update and add - possibly with an associated warning, but I think I do agree with the decision to drop them.
The text was updated successfully, but these errors were encountered:
My understanding is that
SortedList.extend
was removed because there was some sort of efficiency concern, and it was deemed preferable for people to useSortedList.update
. Similarly,SortedList.append
throws an error and it is preferable for people to useadd
.I guess the reasoning here is that
append
andextend
are not actually meaningful concepts to aSortedList
(since "append" means "add to the end" not "add in sorted order).However, throwing
NotImpementedError
breaks Liskov substitution forSortedList
- it's not actually aMutableSequence
, since aMutableSequence
is guaranteed to haveextend
andappend
methods. This is a problem because code that uses type hinting to acceptMutableSequence
, or dispatches based on type is expecting to be able to use these methods.I think it would be best to drop
MutableSequence
as a base class in favor ofSequence
and make sure that these methods are actually not implemented (either using the__getattr__
trick used inSortedDict
or just by dropping them entirely) so thatisinstance
checks will properly fail.An alternative would be to accept a lesser Liskov substitution violation and make them aliases for
update
andadd
- possibly with an associated warning, but I think I do agree with the decision to drop them.The text was updated successfully, but these errors were encountered: