[Python-ideas] Fixing the Python 3 bytes constructor

Donald Stufft donald at stufft.io
Wed Apr 2 14:17:29 CEST 2014


On Apr 2, 2014, at 8:16 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> 
> On 2 Apr 2014 22:01, "Donald Stufft" <donald at stufft.io> wrote:
> >
> >
> > On Apr 2, 2014, at 7:40 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> >
> >>
> >> On 2 Apr 2014 12:52, "Ethan Furman" <ethan at stoneleaf.us> wrote:
> >> >
> >> > On 04/01/2014 09:30 AM, Guido van Rossum wrote:
> >> >
> >> >>>> On Sat, Mar 29, 2014 at 7:17 PM, Nick Coghlan wrote:
> >> >>>>>
> >> >>>>>
> >> >>>>>  x = bytes.byte(data[0])
> >> >>
> >> >>
> >> >> Hm. I don't find that very attractive. You can't write Python 2/3 code using that idiom, and it's a lot longer than the
> >> >> original. The only redeeming feature is that it clearly fails when data is empty, and possibly that you don't have to
> >> >> compute the second index (which could be awkward if the first index is an expression).
> >> >>
> >> >> I'm not denying that we need bytes.byte(), but this doesn't sound like much of a motivation. Just pointing to the need
> >> >> of bytes/bytestring equivalents for chr() makes more sense to me.
> >> >
> >> >
> >> > We already have ord() and chr() -- maybe we should just add byte().
> >>
> >> I thought of that, but it seems like a recipe for typos and confusion. bytes.byte and bytearray.byte seem clearer and safer.
> >>
> >> Cheers,
> >> Nick.
> >>
> >>
> >
> > I don’t like byte(), way to much potential for confusion with bytes(), but maybe bchr() is a reasonable thing.
> 
> There's no need for it to be a builtin at all. The class method alternative constructor approach handles the problem just fine.
> 
> Cheers,
> Nick
> 
> 

I don’t much care which way it goes, I was just mentioning it as an alternative :)


-----------------
Donald Stufft
PGP: 0x6E3CBCE93372DCFA // 7C6B 7C5D 5E2B 6356 A926 F04F 6E3C BCE9 3372 DCFA

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140402/f3171b6e/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140402/f3171b6e/attachment-0001.sig>


More information about the Python-ideas mailing list