Vinay Sajip wrote: > You're right to be nervous: it's not hard to mangle subtypes. > >>>> class mystr(str): pass > ... >>>> s = mystr("Abc") >>>> s > 'Abc' >>>> type(s) > <class '__main__.mystr'> >>>> s2 = s.replace("A", "a") >>>> s2 > 'abc' >>>> type(s2) > <type 'str'>
It's also difficult for the subclass to prevent this without creating an infinite loop... (I only spent about 10 minutes looking into it the other day, but that's what happened in all of my naive attempts at doing it in pure Python code). Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia --------------------------------------------------------------- _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com