This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: The array module and the buffer interface
Type: enhancement Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: josiahcarlson, rhettinger
Priority: normal Keywords:

Created on 2005-04-26 06:59 by josiahcarlson, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
array_frombuffer.diff josiahcarlson, 2005-04-28 20:50 Adds buffer check in array_new, documention, and test cases.
Messages (9)
msg54455 - (view) Author: Josiah Carlson (josiahcarlson) * (Python triager) Date: 2005-04-26 06:59
It would be terribly convenient if array objects were
willing to take any object supporting the buffer
interface as initialization or extension via
a.fromstring().

They currently offer the buffer interface for other
objects to read/write once the array has been created,
but they do not accept buffers during creation or
extension (except for the typecode 'c').
msg54456 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2005-04-28 05:20
Logged In: YES 
user_id=80475

Do you have a patch?
msg54457 - (view) Author: Josiah Carlson (josiahcarlson) * (Python triager) Date: 2005-04-28 06:37
Logged In: YES 
user_id=341410

Not right now, but I could probably have one for you
tomorrow.  You want doc updates and tests too?
msg54458 - (view) Author: Josiah Carlson (josiahcarlson) * (Python triager) Date: 2005-04-28 12:39
Logged In: YES 
user_id=341410

I couldn't sleep, so I started working on it.

Note: a.fromstring(buf_obj) works in Python 2.3 and 2.4, it
just isn't documented, nor is it exposed via array_new.

I've got less than 20 lines of changes that seem to be
necessary for array(typecode, buf) to be supported,
including documentation and unittest updates.  I'll sleep on
it (I'm getting tired) and upload it tomorrow.
msg54459 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2005-06-03 01:12
Logged In: YES 
user_id=80475

+0  It is not unreasonable to want to generalize the
interface.  OTOH, the str() workaround is trivial and explicit:

>>> buf = buffer('abcdefghi', 1, 5)
>>> array('b', str(buf))
array('b', [98, 99, 100, 101, 102])
msg54460 - (view) Author: Josiah Carlson (josiahcarlson) * (Python triager) Date: 2005-06-03 02:04
Logged In: YES 
user_id=341410

I had assumed str(buf) copied the contents of the buffer,
but I was mistaken (read the source Josiah).

As I stated in my previous post, array.fromstring takes
buffer objects, so the documentation should be updated in
that case, which I can do if desired.

Honestly, I am also +0 on the patch.  I think it is
convenient for completeness sake, but with array.fromstring,
and str(buf) being fast, it isn't necessary.
msg54461 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2005-06-03 06:42
Logged In: YES 
user_id=80475

I recommend dropping this one and leaving the API alone. 
The improvement would be so small that it isn't worth the
time to review it, test it, and introduce another version
incompatability (something that runs on Py2.5 that won't run
on Py2.4).
msg54462 - (view) Author: Josiah Carlson (josiahcarlson) * (Python triager) Date: 2005-06-03 06:50
Logged In: YES 
user_id=341410

Sounds reasonable.

What about updating the documentation for array.fromstring()
to acknowledge that it accepts buffer objects, or do we call
it an 'undocumented and untested bonus feature'?
msg54463 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2005-06-03 10:52
Logged In: YES 
user_id=80475

No need for a doc update either. The docs rarely make
promises about the substitutability of lookalike objects. 
For instance, almost nothing that accepts a file argument
documents accepting StringIO objects or other lookalikes.  
 
History
Date User Action Args
2022-04-11 14:56:11adminsetgithub: 41902
2005-04-26 06:59:50josiahcarlsoncreate