<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Aug 17, 2014, at 11:33 AM, Ethan Furman <<a href="mailto:ethan@stoneleaf.us">ethan@stoneleaf.us</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span style="font-family: ArialMT; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;">I've had many of the problems Nick states and I'm also +1.</span><br style="font-family: ArialMT; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"></blockquote><br></div><div>There are two code snippets below which were taken from the standard library.</div><div>Are you saying that:</div><div>1) you don't understand the code (as the pep suggests)</div><div>2) you are willing to break that code and everything like it</div><div>3) and it would be more elegantly expressed as:  </div><div>        charmap = bytearray.zeros(256)</div><div>    and</div><div>        mapping = bytearray.zeros(256)</div><div><br></div><div>At work, I have network engineers creating IPv4 headers and other structures</div><div>with bytearrays initialized to zeros.  Do you really want to break all their code?</div><div>No where else in Python do we create buffers that way.  Code like</div><div>"msg, who = s.recvfrom(256)" is the norm.</div><div><br></div><div>Also, it is unclear if you're saying that you have an actual use case for this</div><div>part of the proposal?</div><div><br></div><div>   ba = bytearray.byte(65)</div><div><br></div><div>And than the code would be better, clearer, and faster than the currently working form?</div><div><br></div><div>   ba = bytearray([65])</div><div><br></div><div>Does there really need to be a special case for constructing a single byte?</div><div>To me, that is akin to proposing "list.from_int(65)" as an important special</div><div>case to replace "[65]".</div><div><br></div><div>If you must muck with the ever changing bytes() API, then please </div><div>leave the bytearray() API alone.  I think we should show some respect</div><div>for code that is currently working and is cleanly expressible in both</div><div>Python 2 and Python 3.  We aren't winning users with API churn.</div><div><br></div><div>FWIW, I guessing that the differing view points in the thread stem</div><div>mainly from the proponents experiences with bytes() rather than</div><div>from experience with bytearray() which doesn't seem to have any</div><div>usage problems in the wild.  I've never seen a developer say they</div><div>didn't understand what "buf = bytearray(1024)" means.   That is</div><div>not an actual problem that needs solving (or breaking).</div><div><br></div><div>What may be an actual problem is code like "char = bytes(1024)"</div><div>though I'm unclear what a user might have actually been trying</div><div>to do with code like that.</div><div><br></div><div><br></div><div>Raymond</div><div><br></div><div><br></div><div>----------- excerpts from Lib/sre_compile.py ---------------</div><div><br></div><div><div>    charmap = bytearray(256)</div><div>    for op, av in charset:</div><div><span class="Apple-tab-span" style="white-space:pre">       </span>while True:</div><div>            try:</div><div>                if op is LITERAL:</div><div>                    charmap[fixup(av)] = 1</div><div>                elif op is RANGE:</div><div>                    for i in range(fixup(av[0]), fixup(av[1])+1):</div><div>                        charmap[i] = 1</div><div>                elif op is NEGATE:</div><div>                    out.append((op, av))</div><div>                else:</div><div>                    tail.append((op, av))</div><div><br></div><div>    ...</div><div><br></div><div>    charmap = bytes(charmap) # should be hashable                                                                                 </div><div>    comps = {}</div><div>    mapping = bytearray(256)</div><div>    block = 0</div><div>    data = bytearray()</div><div>    for i in range(0, 65536, 256):</div><div>        chunk = charmap[i: i + 256]</div><div>        if chunk in comps:</div><div>            mapping[i // 256] = comps[chunk]</div><div>        else:</div><div>            mapping[i // 256] = comps[chunk] = block</div><div>            block += 1</div><div>            data += chunk</div><div>    data = _mk_bitmap(data)</div><div>    data[0:0] = [block] + _bytes_to_codes(mapping)</div><div>    out.append((BIGCHARSET, data))</div><div>    out += tail</div><div>    return out                    </div></div></body></html>