[Python-Dev] Re: Parameters of str(), bytes() and bytearray()

2019-12-16 Thread Terry Reedy
The docstring is left not fixed.     str(object='') -> str     str(bytes_or_buffer[, encoding[, errors]]) -> str I noticed this too; the doc and docstring should be made to agree with each other and the code. While exploring the actual behavior, I discovered that while the presence of e

[Python-Dev] Re: Parameters of str(), bytes() and bytearray()

2019-12-16 Thread Guido van Rossum
On Mon, Dec 16, 2019 at 12:04 PM Serhiy Storchaka wrote: > 16.12.19 18:35, Guido van Rossum пише: > > On Sun, Dec 15, 2019 at 6:09 AM Serhiy Storchaka > > wrote: > > > > 1. Forbids calling str() without object if encoding or errors are > > specified. It is ver

[Python-Dev] Re: Parameters of str(), bytes() and bytearray()

2019-12-16 Thread Serhiy Storchaka
16.12.19 18:35, Guido van Rossum пише: On Sun, Dec 15, 2019 at 6:09 AM Serhiy Storchaka > wrote: 1. Forbids calling str() without object if encoding or errors are specified. It is very unlikely that this can break a real code, so I propose to make it an er

[Python-Dev] Re: Parameters of str(), bytes() and bytearray()

2019-12-16 Thread David Mertz
On Mon, Dec 16, 2019 at 4:06 AM Serhiy Storchaka wrote: > 15.12.19 16:30, David Mertz пише: > > I bet someone in the world has written code like: > > > > foo = str(**dynamic_args()) > > > > And therefore, disabling "silly" combinations of arguments will break > > their code occasionally. > > Do y

[Python-Dev] Re: Parameters of str(), bytes() and bytearray()

2019-12-16 Thread Guido van Rossum
On Sun, Dec 15, 2019 at 6:09 AM Serhiy Storchaka wrote: > Currently str() takes up to 3 arguments. All are optional and > positional-or-keyword. All combinations are valid: > > str() > str(object=object) > str(object=buffer, encoding=encoding) > str(object=buffer, errors=errors) > str(object=buff

[Python-Dev] Re: Parameters of str(), bytes() and bytearray()

2019-12-16 Thread Kyle Stanley
Kyle Stanley wrote: > or making *object* a positional only argument. Typo: I meant "positional only parameter", not "argument". On Mon, Dec 16, 2019 at 4:39 AM Kyle Stanley wrote: > > Inada Naoki wrote: > > If we find it broke some software, we can step back to regular > > deprecation workflow.

[Python-Dev] Re: Parameters of str(), bytes() and bytearray()

2019-12-16 Thread Kyle Stanley
Inada Naoki wrote: > If we find it broke some software, we can step back to regular > deprecation workflow. > Python 3.9 is still far from beta yet. That's why I'm +1 on these proposals. IMO, since this would be changing a builtin function, we should at least use a version+2 deprecation cycle (in

[Python-Dev] Re: Parameters of str(), bytes() and bytearray()

2019-12-16 Thread Inada Naoki
On Mon, Dec 16, 2019 at 6:25 PM Inada Naoki wrote: > > +1 for 1 and 2. > If we find it broke some software, we can step back to regular deprecation workflow. Python 3.9 is still far from beta yet. That's why I'm +1 on these proposals. -- Inada Naoki __

[Python-Dev] Re: Parameters of str(), bytes() and bytearray()

2019-12-16 Thread Inada Naoki
On Sun, Dec 15, 2019 at 11:07 PM Serhiy Storchaka wrote: > > I propose several changes: > > 1. Forbids calling str() without object if encoding or errors are > specified. It is very unlikely that this can break a real code, so I > propose to make it an error without a deprecation period. > > 2. Ma

[Python-Dev] Re: Parameters of str(), bytes() and bytearray()

2019-12-16 Thread Kyle Stanley
Serhiy Storchaka wrote: > It is not more confusing that returning "". By > default str() returns the same as repr(), unless we made the object > having other string representation. Yeah, I suppose not. But that does raise of question of why bytes objects were made to have a specific form of string

[Python-Dev] Re: Parameters of str(), bytes() and bytearray()

2019-12-16 Thread Serhiy Storchaka
16.12.19 10:34, Eric V. Smith пише: On 12/16/2019 3:05 AM, Kyle Stanley wrote: Chris Angelico wrote: > ANY object can be passed to str() in order to get some sort of valid > printable form. The awkwardness comes from the fact that str() > performs double duty - it's both "give me a printable for

[Python-Dev] Re: Parameters of str(), bytes() and bytearray()

2019-12-16 Thread Kyle Stanley
Eric V. Smith wrote: > Debugging. I sometimes do things like: print('\n'.join(str(thing) for thing in lst)), or various variations on this. This is especially useful > when maybe something in the list is a bytes object where I was expecting a string. > > I'm not saying it's the best practice, but c

[Python-Dev] Re: Parameters of str(), bytes() and bytearray()

2019-12-16 Thread Serhiy Storchaka
15.12.19 16:30, David Mertz пише: I bet someone in the world has written code like: foo = str(**dynamic-args()) And therefore, disabling "silly" combinations of arguments will break their code occasionally. Do you have real world examples? ___ Pyth

[Python-Dev] Re: Parameters of str(), bytes() and bytearray()

2019-12-16 Thread Serhiy Storchaka
16.12.19 02:55, Kyle Stanley пише: I'd much prefer to see something like this: >>> str(b'\xc3\xa1') ... TypeError: bytes argument without an encoding Is there some use case for returning "b'\\xc3\\xa1'" from this operation that I'm not seeing? To me, it seems equally, if not more confusing and

[Python-Dev] Re: Parameters of str(), bytes() and bytearray()

2019-12-16 Thread Eric V. Smith
On 12/16/2019 3:05 AM, Kyle Stanley wrote: Chris Angelico wrote: > ANY object can be passed to str() in order to get some sort of valid > printable form. The awkwardness comes from the fact that str() > performs double duty - it's both "give me a printable form of this > object" and "decode these

[Python-Dev] Re: Parameters of str(), bytes() and bytearray()

2019-12-16 Thread Glenn Linderman
On 12/16/2019 12:05 AM, Kyle Stanley wrote: Chris Angelico wrote: > ANY object can be passed to str() in order to get some sort of valid > printable form. The awkwardness comes from the fact that str() > performs double duty - it's both "give me a printable form of this > object" and "decode thes

[Python-Dev] Re: Parameters of str(), bytes() and bytearray()

2019-12-16 Thread Kyle Stanley
Chris Angelico wrote: > ANY object can be passed to str() in order to get some sort of valid > printable form. The awkwardness comes from the fact that str() > performs double duty - it's both "give me a printable form of this > object" and "decode these bytes into text". While it does make sense

[Python-Dev] Re: Parameters of str(), bytes() and bytearray()

2019-12-15 Thread Chris Angelico
On Mon, Dec 16, 2019 at 12:00 PM Kyle Stanley wrote: > On a related note though, I'm not a fan of this behavior: > >>> str(b'\xc3\xa1') > "b'\\xc3\\xa1'" > > Passing a bytes object to str() without specifying an encoding seems like a > mistake, I honestly don't see how this ("b'\\xc3\\xa1'") woul

[Python-Dev] Re: Parameters of str(), bytes() and bytearray()

2019-12-15 Thread Kyle Stanley
Serhiy Storchaka wrote: > Forbids calling str() without object if encoding or errors are > specified. It is very unlikely that this can break a real code, so I > propose to make it an error without a deprecation period. +1, I suspect that nobody would intentionally pass an argument to the encoding

[Python-Dev] Re: Parameters of str(), bytes() and bytearray()

2019-12-15 Thread David Mertz
I bet someone in the world has written code like: foo = str(**dynamic-args()) And therefore, disabling "silly" combinations of arguments will break their code occasionally. On Sun, Dec 15, 2019, 9:09 AM Serhiy Storchaka wrote: > Currently str() takes up to 3 arguments. All are optional and > p