[issue27572] Support bytes-like objects when base is given to int()

2018-09-17 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
versions: +Python 3.8 -Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27572] Support bytes-like objects when base is given to int()

2017-03-23 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Created PR 779 for the deprecation.

--
stage:  -> patch review
versions: +Python 3.7 -Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27572] Support bytes-like objects when base is given to int()

2017-03-23 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
pull_requests: +683

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27572] Support bytes-like objects when base is given to int()

2016-09-27 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


Added file: 
http://bugs.python.org/file44841/deprecate_byte_like_support_in_int.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27572] Support bytes-like objects when base is given to int()

2016-09-27 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


Removed file: 
http://bugs.python.org/file44840/deprecate_byte_like_support_in_int.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27572] Support bytes-like objects when base is given to int()

2016-09-27 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Here is a patch that deprecates support of bytes-like objects except bytes and 
bytearray in int(), float(), compile(), eval(), exec(). I'm not arguing for it, 
this is just for the ground of the discussion.

--
Added file: 
http://bugs.python.org/file44840/deprecate_byte_like_support_in_int.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27572] Support bytes-like objects when base is given to int()

2016-07-23 Thread Xiang Zhang

Xiang Zhang added the comment:

pypy seems so.

[PyPy 5.2.0-alpha0 with GCC 4.8.2] on linux
 int(memoryview(b'123A'[1:3]))
23
 int(memoryview(b'123 '[1:3]))
23

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27572] Support bytes-like objects when base is given to int()

2016-07-22 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

No, the fix was applied to all maintained versions (2.7 and 3.4+). This means 
that we need some deprecation period before dropping this feature (if decide to 
drop it).

What about other Python implementations? Are they support byte-likes objects 
besides bytes and bytearray? Do they correctly handle embedded NUL and 
not-NUL-terminated buffers?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27572] Support bytes-like objects when base is given to int()

2016-07-22 Thread R. David Murray

R. David Murray added the comment:

So less than a year means only some versions of 3.5?  So we could drop it in 
3.6 and hope we don't break anybody's code?  I'm not sure I like that...I think 
the real problem is the complexity of handling multiple bytes types, and that 
ought to have a more general solution.  I'm not volunteering to work on it, 
though, so I'm not voting against dropping it.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27572] Support bytes-like objects when base is given to int()

2016-07-22 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

It looks to me that the support of bytes-like objects besides bytes and 
bytearray was added accidentally, as a side effect of supporting Unicode. Note, 
that this support had a bug until issue24802, thus correct support of other 
bytes-like objects exists less than a year. The option of deprecating other 
bytes-like objects support looks reasonable to me. Especially in the light of 
deprecating bytearray paths support (issue26800).

On other side, the need of copying a buffer can be considered as implementation 
detail, since low-level int parsing functions require NUL-terminated C strings. 
We can add alternative low-level functions that work with not-NUL-terminated 
strings. This needs more work.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27572] Support bytes-like objects when base is given to int()

2016-07-22 Thread R. David Murray

R. David Murray added the comment:

Since bytes are accepted in both cases, the inconsistency does seem odd.  
Looking at the history, I think the else statement that checks the types that 
can be handled was introduced during the initial py3k conversion, and I'm 
guessing that else was just forgotten in subsequent updates that added 
additional bytes-like types.  The non-base branch calls PyNumber_Long, where I 
presume it picked up the additional type support.

If a copy has to be done anyway, perhaps we can future proof the code by doing 
a bytes conversion internally in long_new?

Disallowing something that currently works without a good reason isn't good for 
backward compatibility, so I'd vote for making this work consistently one way 
or another.

--
nosy: +r.david.murray

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27572] Support bytes-like objects when base is given to int()

2016-07-22 Thread Xiang Zhang

Xiang Zhang added the comment:

It's reasonable. My original intention is to make the behaviour consistent. If 
the single-argument behaviour is OK with bytes-like objects, why not others? So 
I think we'd better wait for other developers to see what their opinions are.

--
nosy: +rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27572] Support bytes-like objects when base is given to int()

2016-07-22 Thread Martin Panter

Martin Panter added the comment:

I am torn on this. On one hand, it would be good to be consistent with the 
single-argument behaviour. But on the other hand, APIs normally accept 
arbitrary bytes-like objects (like memoryview) to minimise unnecessary copying, 
whereas this case has to make a copy to append a null terminator.

Perhaps another option is to deprecate int(byteslike) support instead, in 
favour of explicitly making a copy using bytes(byteslike). Similarly for float, 
compile, eval, exec, which also do copying thanks to Issue 24802. But 
PyNumber_Long() has called PyObject_AsCharBuffer() (predecessor of Python 3’s 
bytes-like objects) since 1.5.2 (revision 74b7213fb609). So this option would 
probably need wider discussion.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27572] Support bytes-like objects when base is given to int()

2016-07-21 Thread Xiang Zhang

Xiang Zhang added the comment:

Thanks for the reviews Martin. Change the doc and test.

--
Added file: http://bugs.python.org/file43825/bytes_like_support_to_int_v2.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27572] Support bytes-like objects when base is given to int()

2016-07-19 Thread Xiang Zhang

Changes by Xiang Zhang :


Added file: http://bugs.python.org/file43790/bytes_like_support_to_int.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27572] Support bytes-like objects when base is given to int()

2016-07-19 Thread Xiang Zhang

Changes by Xiang Zhang :


Removed file: http://bugs.python.org/file43789/bytes_like_support_to_int.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27572] Support bytes-like objects when base is given to int()

2016-07-19 Thread Xiang Zhang

Changes by Xiang Zhang :


--
type:  -> enhancement

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27572] Support bytes-like objects when base is given to int()

2016-07-19 Thread Xiang Zhang

New submission from Xiang Zhang:

Right now, int() supports bytes-like objects when *base* is not given:

>>> int(memoryview(b'100'))
100

When *base* is given bytes-like objects are not supported:

>>> int(memoryview(b'100'), base=2)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: int() can't convert non-string with explicit base

Is there any obvious reason not to support it when *base* is given? I suggest 
add it.

--
components: Interpreter Core
files: bytes_like_support_to_int.patch
keywords: patch
messages: 270818
nosy: martin.panter, xiang.zhang
priority: normal
severity: normal
status: open
title: Support bytes-like objects when base is given to int()
versions: Python 3.6
Added file: http://bugs.python.org/file43789/bytes_like_support_to_int.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com