[Python-Dev] Re: PEP 467: Minor bytes and bytearray improvements

2021-11-09 Thread Victor Stinner
On Mon, Nov 8, 2021 at 8:21 PM Ethan Furman wrote: > The difference with the built-in ascii is the absence of extra quotes and the > `b` indicator when a string is used: > > ``` > >>> u_var = u'abc' > >>> bytes.ascii(u_var) > b'abc' What about bytes, bytearray and memoryview? What is the

[Python-Dev] Re: PEP 467: Minor bytes and bytearray improvements

2021-11-08 Thread Ethan Furman
On 11/8/21 4:45 AM, Victor Stinner wrote: > Is it implement "like" ascii(obj).encode("ascii") but with minor > changes? What changes? It works like `str()`, but you get ascii-encoded bytes (or an exception if that's not possible). The difference with the built-in ascii is the absence of extra

[Python-Dev] Re: PEP 467: Minor bytes and bytearray improvements

2021-11-08 Thread Victor Stinner
The ascii() constructor is not well specified by the PEP. There are only a few examples. I don't understand how it's supposed by be implemented. Would you mind to elaborate its specification? Is it implement "like" ascii(obj).encode("ascii") but with minor changes? What changes? Victor

[Python-Dev] Re: PEP 467: Minor bytes and bytearray improvements

2021-11-04 Thread Chris Angelico
On Fri, Nov 5, 2021 at 2:59 AM Jonathan Goble wrote: > > On Thu, Nov 4, 2021 at 10:37 AM Eric Fahlgren wrote: >> >> On Thu, Nov 4, 2021 at 12:01 AM Ethan Furman wrote: >>> >>> >>> bytearray.fromsize(5, fill=b'\x0a') >>> bytearray(b'\x0a\x0a\x0a\x0a\x0a') >> >> >> What happens if you

[Python-Dev] Re: PEP 467: Minor bytes and bytearray improvements

2021-11-04 Thread Jonathan Goble
On Thu, Nov 4, 2021 at 10:37 AM Eric Fahlgren wrote: > On Thu, Nov 4, 2021 at 12:01 AM Ethan Furman wrote: > >> >>> bytearray.fromsize(5, fill=b'\x0a') >> bytearray(b'\x0a\x0a\x0a\x0a\x0a') >> > > What happens if you supply more than one byte for the fill argument? > Silent

[Python-Dev] Re: PEP 467: Minor bytes and bytearray improvements

2021-11-04 Thread Eric Fahlgren
On Thu, Nov 4, 2021 at 12:01 AM Ethan Furman wrote: > >>> bytearray.fromsize(5, fill=b'\x0a') > bytearray(b'\x0a\x0a\x0a\x0a\x0a') > What happens if you supply more than one byte for the fill argument? Silent truncation, raise ValueError('too long') or ???