Can someone explain the following behaviour:
class derivedset1(frozenset):
def __new__(cls,*args):
return frozenset.__new__(cls,args)
class derivedset2(set):
def __new__(cls,*args):
return set.__new__(cls,args)
a=derivedset1('item1','item2') # WORKS
b=derivedset2('item1','item2') # DOESN'T WORK
Traceback (most recent call last):
File "inheriting-behaviours.py", line 12, in <module>
b=derivedset2('item1','item2') # DOESN'T WORK
TypeError: derivedset2 expected at most 1 arguments, got 2
This is surprising to me that you can alter the constructor of a frozen set whereas it is not possible for the constructor of a mutable set.
b=derivedset2(['item1','item2'])
works. – Betteann