Re: unicode(obj, errors='foo') raises TypeError - bug?

2005-02-23 Thread Kent Johnson
Steven Bethard wrote: Mike Brown wrote: class C: ... def __str__(self): ... return 'asdf\xff' ... o = C() unicode(o, errors='replace') Traceback (most recent call last): File stdin, line 1, in ? TypeError: coercing to Unicode: need string or buffer, instance found [snip] What am I doing

Re: unicode(obj, errors='foo') raises TypeError - bug?

2005-02-23 Thread Steven Bethard
Kent Johnson wrote: Steven Bethard wrote: No, this is documented behavior[1]: unicode([object[, encoding [, errors]]]) ... For objects which provide a __unicode__() method, it will call this method without arguments to create a Unicode string. For all other objects, the 8-bit string

Re: unicode(obj, errors='foo') raises TypeError - bug?

2005-02-23 Thread Martin v. Lwis
Steven Bethard wrote: Yeah, I agree it's weird. I suspect if someone supplied a patch for this behavior it would be accepted -- I don't think this should break backwards compatibility (much). Notice that the right thing to do would be to pass encoding and errors to __unicode__. If the string

Re: unicode(obj, errors='foo') raises TypeError - bug?

2005-02-23 Thread Kent Johnson
Martin v. Lwis wrote: Steven Bethard wrote: Yeah, I agree it's weird. I suspect if someone supplied a patch for this behavior it would be accepted -- I don't think this should break backwards compatibility (much). Notice that the right thing to do would be to pass encoding and errors to

Re: unicode(obj, errors='foo') raises TypeError - bug?

2005-02-23 Thread Martin v. Lwis
Kent Johnson wrote: Could this be handled with a try / except in unicode()? Something like this: Perhaps. However, this would cause a significant performance hit, and possbibly undesired side effects. So due process would require that the interface of __unicode__ first, and then change the actual

unicode(obj, errors='foo') raises TypeError - bug?

2005-02-22 Thread Mike Brown
This works as expected (this is on an ASCII terminal): unicode('asdf\xff', errors='replace') u'asdf\ufffd' This does not work as I expect it to: class C: ... def __str__(self): ... return 'asdf\xff' ... o = C() unicode(o, errors='replace') Traceback (most recent call last): File

Re: unicode(obj, errors='foo') raises TypeError - bug?

2005-02-22 Thread Steven Bethard
Mike Brown wrote: class C: ... def __str__(self): ... return 'asdf\xff' ... o = C() unicode(o, errors='replace') Traceback (most recent call last): File stdin, line 1, in ? TypeError: coercing to Unicode: need string or buffer, instance found [snip] What am I doing wrong? Is this a bug in