Python, subclassing immutable types
Yes, you need to override __new__
special method:
class MySet(frozenset):
def __new__(cls, *args):
if args and isinstance (args[0], basestring):
args = (args[0].split (),) + args[1:]
return super (MySet, cls).__new__(cls, *args)
print MySet ('foo bar baz')
And the output is:
MySet(['baz', 'foo', 'bar'])