[IronPython] Minor bug in conversion of str to bytes?

Dino Viehland dinov at microsoft.com
Sat May 30 00:13:00 CEST 2009


Because in IronPython str is just an alias for Unicode.  I think it would
be extremely broken for us to alias all 3 to unicode especially when bytes
clearly has a different meaning.

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord
Sent: Friday, May 29, 2009 11:34 AM
To: Discussion of IronPython
Subject: Re: [IronPython] Minor bug in conversion of str to bytes?

Dino Viehland wrote:
> Unfortunately there's probably going to continue to be a bunch of corner
> cases related to bytes/str/unicode until we move to 3.0.  But hopefully
> we can come up w/ reasonable workarounds for most of them.
>
> In this case it seems like we should define __str__ on bytes and make
> it return a Unicode string w/o the b''.  We can keep repr in there so
> that an explicit repr still gives you the b'' representation...
>
> Ahh, I can't wait until Ipy 3.0!
>

In Python 2.6 the bytes type is just an alias for str I believe, am I
incorrect? If I am correct why is IronPython 2.6 taking a different
approach?

Michael

>
> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Robert Smallshire
> Sent: Friday, May 29, 2009 10:29 AM
> To: 'Discussion of IronPython'
> Subject: [IronPython] Minor bug in conversion of str to bytes?
>
> Hello,
>
> Lets create a bytes instance from a str, and convert it back to a str.
>
>
>>>> a = bytes(ord(c) for c in "Hello World")
>>>> a
>>>>
> b'Hello World'
>
>>>> str(a)
>>>>
> "b'Hello World'"
>
> As you can see, the leading b and the quotes become part of the string,
> which is unexpected.  I guess the conversion is using __repr__ where it
> should use __str__.
>
> Cheers,
>
> Rob
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>


--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog


_______________________________________________
Users mailing list
Users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Ironpython-users mailing list