Type subclassing: bug or feature
David LeBlanc
whisper at oz.net
Thu Jun 13 17:14:49 EDT 2002
> -----Original Message-----
> From: python-list-admin at python.org
> [mailto:python-list-admin at python.org]On Behalf Of Aahz
> Sent: Thursday, June 13, 2002 13:09
> To: python-list at python.org
> Subject: Type subclassing: bug or feature
>
>
> Consider the following code:
>
> class MyStr(str):
> def contains(self, value):
> return self.find(value) >= 0
>
> s = MyStr("hello, world!")
> s = s.capitalize()
> if s.contains('Hello'):
> print "Found it!"
>
> It fails with an AttributeError when it calls s.contains(), because
> s.capitalize() returned a str instead of a MyStr. Anyone want to take a
> whack at defending this as the correct behavior?
> --
> Aahz (aahz at pythoncraft.com) <*>
> http://www.pythoncraft.com/
Looks like a bug to me. How can self be something else then what it is?
Should MySocket return a socket, thus stripping off any additional
functionality added by my derived class?
David LeBlanc
Seattle, WA USA
More information about the Python-list
mailing list