Re: [Python-Dev] __str__ vs. __unicode__

2005-02-24 Thread Brett C.
Brett C. wrote: Walter Dörwald wrote: Brett C. wrote: Walter Dörwald wrote: M.-A. Lemburg wrote: [...] I don't have a clear picture of what the consensus currently looks like :-) If we're going for for a solution that implements the hook awareness for all hooks, I'd be +1 on that. If we only t

Re: [Python-Dev] __str__ vs. __unicode__

2005-02-24 Thread Brett C.
Walter Dörwald wrote: Brett C. wrote: Walter Dörwald wrote: M.-A. Lemburg wrote: [...] I don't have a clear picture of what the consensus currently looks like :-) If we're going for for a solution that implements the hook awareness for all hooks, I'd be +1 on that. If we only touch the __unico

Re: [Python-Dev] __str__ vs. __unicode__

2005-02-24 Thread Walter Dörwald
Brett C. wrote: Walter Dörwald wrote: M.-A. Lemburg wrote: [...] I don't have a clear picture of what the consensus currently looks like :-) If we're going for for a solution that implements the hook awareness for all hooks, I'd be +1 on that. If we only touch the __unicode__ case, we'd only b

Re: [Python-Dev] __str__ vs. __unicode__

2005-02-23 Thread Brett C.
Walter Dörwald wrote: M.-A. Lemburg wrote: Walter Dörwald wrote: M.-A. Lemburg wrote: > [...] __str__ and __unicode__ as well as the other hooks were specifically added for the type constructors to use. However, these were added at a time where sub-classing of types was not possible, so it's time

Re: [Python-Dev] __str__ vs. __unicode__

2005-01-25 Thread Walter Dörwald
M.-A. Lemburg wrote: Walter Dörwald wrote: M.-A. Lemburg wrote: > [...] __str__ and __unicode__ as well as the other hooks were specifically added for the type constructors to use. However, these were added at a time where sub-classing of types was not possible, so it's time now to reconsider whet

Re: [Python-Dev] __str__ vs. __unicode__

2005-01-23 Thread M.-A. Lemburg
Walter Dörwald wrote: M.-A. Lemburg wrote: > [...] __str__ and __unicode__ as well as the other hooks were specifically added for the type constructors to use. However, these were added at a time where sub-classing of types was not possible, so it's time now to reconsider whether this functionalit

Re: [Python-Dev] __str__ vs. __unicode__

2005-01-21 Thread Walter Dörwald
M.-A. Lemburg wrote: > [...] __str__ and __unicode__ as well as the other hooks were specifically added for the type constructors to use. However, these were added at a time where sub-classing of types was not possible, so it's time now to reconsider whether this functionality should be extended to

Re: [Python-Dev] __str__ vs. __unicode__

2005-01-19 Thread Walter Dörwald
Nick Coghlan wrote: [...] I imagine many people are like me, with __str__ being the only one of these hooks they use frequently (Helping out with the Decimal implementation is the only time I can recall using the slots for the numeric types, and I rarely need to deal with Unicode). Anyway, they

Re: [Python-Dev] __str__ vs. __unicode__

2005-01-19 Thread Aahz
On Wed, Jan 19, 2005, Walter D?rwald wrote: > M.-A. Lemburg wrote: >> >>Maybe the string case is the real problem ... :-) > > At least it seems that the string case is the exception. > So if we fix __str__ this would be a bugfix for 2.4.1. Nope. Unless you're claiming the __str__ behavior is ne

Re: [Python-Dev] __str__ vs. __unicode__

2005-01-19 Thread Nick Coghlan
M.-A. Lemburg wrote: Those APIs were all written long before there were sub-classes of types. Understood. PyObject_Unicode certainly looked like an 'evolved' piece of code :) But before we start hacking the function, we need a general picture of what we think is right. Aye. Note, BTW, that there i

Re: [Python-Dev] __str__ vs. __unicode__

2005-01-19 Thread M.-A. Lemburg
Nick Coghlan wrote: M.-A. Lemburg wrote: So if we fix __str__ this would be a bugfix for 2.4.1. If we fix the rest, this would be a new feature for 2.5. I have a feeling that we're better off with the bug fix than the new feature. __str__ and __unicode__ as well as the other hooks were specificall

Re: [Python-Dev] __str__ vs. __unicode__

2005-01-19 Thread Nick Coghlan
M.-A. Lemburg wrote: So if we fix __str__ this would be a bugfix for 2.4.1. If we fix the rest, this would be a new feature for 2.5. I have a feeling that we're better off with the bug fix than the new feature. __str__ and __unicode__ as well as the other hooks were specifically added for the type

Re: [Python-Dev] __str__ vs. __unicode__

2005-01-19 Thread M.-A. Lemburg
Walter Dörwald wrote: M.-A. Lemburg wrote: So the question is whether conversion of a Unicode sub-type to a true Unicode object should honor __unicode__ or not. The same question can be asked for many other types, e.g. floats (and __float__), integers (and __int__), etc. >>> class float2(float): .

Re: [Python-Dev] __str__ vs. __unicode__

2005-01-19 Thread Alex Martelli
On 2005 Jan 19, at 11:10, Bob Ippolito wrote: Do you REALLY think this should be True?! isinstance(foo, unicode) and foo != unicode(foo) H -- why not? In the generic case, talking about some class B, it certainly violates no programming principle known to me that "isinstance(foo, B) and

Re: [Python-Dev] __str__ vs. __unicode__

2005-01-19 Thread Walter Dörwald
Bob Ippolito wrote: On Jan 19, 2005, at 4:40, Walter Dörwald wrote: [...] That's cheating! ;) My use case is an XML DOM API: __unicode__() should extract the character data from the DOM. For Text nodes this is the text, for comments and processing instructions this is u"" etc. To reduce memory foot

Re: [Python-Dev] __str__ vs. __unicode__

2005-01-19 Thread Walter Dörwald
M.-A. Lemburg wrote: Walter Dörwald wrote: __str__ and __unicode__ seem to behave differently. A __str__ overwrite in a str subclass is used when calling str(), a __unicode__ overwrite in a unicode subclass is *not* used when calling unicode(): [...] If you drop the base class for unicode, this alr

Re: [Python-Dev] __str__ vs. __unicode__

2005-01-19 Thread Bob Ippolito
On Jan 19, 2005, at 4:40, Walter Dörwald wrote: M.-A. Lemburg wrote: Walter Dörwald wrote: __str__ and __unicode__ seem to behave differently. A __str__ overwrite in a str subclass is used when calling str(), a __unicode__ overwrite in a unicode subclass is *not* used when calling unicode(): [...]

Re: [Python-Dev] __str__ vs. __unicode__

2005-01-18 Thread M.-A. Lemburg
Walter Dörwald wrote: __str__ and __unicode__ seem to behave differently. A __str__ overwrite in a str subclass is used when calling str(), a __unicode__ overwrite in a unicode subclass is *not* used when calling unicode(): --- class str2(str): def __str__(self):

[Python-Dev] __str__ vs. __unicode__

2005-01-18 Thread Walter Dörwald
__str__ and __unicode__ seem to behave differently. A __str__ overwrite in a str subclass is used when calling str(), a __unicode__ overwrite in a unicode subclass is *not* used when calling unicode(): --- class str2(str): def __str__(self): return "foo" x =