[Python-Dev] Re: [I18n-sig] Unicode experience

M.-A. Lemburg mal@lemburg.com
Fri, 07 Jul 2000 14:56:37 +0200


Fredrik Lundh wrote:
> 
> guido wrote:
> > I propose ustr(x) with the semantics given by Toby.
> 
> +1 on concept.
>
> not sure about the name and the semantics.

Uhm, what's left then ;-) ?
 
> maybe a better name would be "unistr" (to match "unistr").
> or maybe that's backwards?
> 
> how about "String" (!).
> 
> (the perfect name is "string", but that appears to be reserved
> by someone else...)
> 
> as for the semantics, note that __str__ is allowed to return a
> unicode string in the current code base ("str" converts it to 8-
> bit using the default encoding).  ustr/unistr/String should pass
> that one right through:
> 
>     def ustr(s):
>         if type(s) in (type(""), type(u"")):
>             return s
>         s = s.__str__()
>         if type(s) in (type(""), type(u"")):
>             return s
>         raise "__str__ returned wrong type"
> 
> > Class support (an __ustr__ method, with fallbacks on __str__
> > and __unicode__) would also be handy.
> 
> -0 on this one (__str__ can already return either type, and if the
> goal is to get rid of both unichr and unistr in the future, we shouldn't
> add more hooks if we can avoid it.  it's easier to remove stuff if you
> don't add them in the first place ;-)

Agreed. I'm just adding coercion support for instances using
that technique: instance defining __str__ can return Unicode
objects which will then be used by the implementation whereever
coercion to Unicode takes place.

I'll add a similar hook to unicode().

-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/