[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-07-29 Thread Eli Bendersky

Changes by Eli Bendersky :


--
status: open -> closed

___
Python tracker 

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



[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-07-28 Thread Eli Bendersky

Eli Bendersky  added the comment:

Petri, thanks for the patch. I've updated Misc/NEWS and committed it.

Unless there are objections or problems, I will close this issue in a day or 
two.

--
resolution:  -> fixed
stage: patch review -> committed/rejected

___
Python tracker 

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



[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-07-28 Thread Roundup Robot

Roundup Robot  added the comment:

New changeset 536fccc75f5a by Eli Bendersky in branch 'default':
Issue #12380: PyArg_ParseTuple now accepts a bytearray for the 'c' format.
http://hg.python.org/cpython/rev/536fccc75f5a

--
nosy: +python-dev

___
Python tracker 

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



[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-07-27 Thread Petri Lehtinen

Petri Lehtinen  added the comment:

Updated the patch to add tests for {bytes,bytearray}.{center,ljust,rjust}. The 
tests check that both bytes and bytearray are always accepted as the fill 
character.

--
Added file: 
http://bugs.python.org/file22779/c_format_bytearray_plus_additional_tests.patch

___
Python tracker 

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



[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-07-27 Thread Eli Bendersky

Eli Bendersky  added the comment:

Looks good. How about also adding some tests for the original request of 
supporting bytearrays in ljust/rjust/center?

--

___
Python tracker 

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



[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-07-26 Thread Petri Lehtinen

Petri Lehtinen  added the comment:

Updated the bytearray patch to change documentation and add tests.

--
Added file: http://bugs.python.org/file22764/c_format_bytearray.patch

___
Python tracker 

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



[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-07-26 Thread Petri Lehtinen

Changes by Petri Lehtinen :


Removed file: http://bugs.python.org/file22757/c_format_buffer.patch

___
Python tracker 

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



[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-07-26 Thread Petri Lehtinen

Changes by Petri Lehtinen :


Removed file: http://bugs.python.org/file22756/c_format_bytearray.patch

___
Python tracker 

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



[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-07-25 Thread Antoine Pitrou

Antoine Pitrou  added the comment:

c_format_bytearray.patch looks ok to me. The other proposal is too broad, and 
may lead to confusing behaviour.
In any case, some tests are needed.

--

___
Python tracker 

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



[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-07-25 Thread Petri Lehtinen

Changes by Petri Lehtinen :


--
keywords: +needs review
stage: needs patch -> patch review

___
Python tracker 

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



[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-07-25 Thread Petri Lehtinen

Changes by Petri Lehtinen :


Added file: http://bugs.python.org/file22757/c_format_buffer.patch

___
Python tracker 

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



[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-07-25 Thread Petri Lehtinen

Petri Lehtinen  added the comment:

> The solution could be global, to allow bytearray fit the 'c' format of
> PyArg_ParseTuple. Then one would also be able to pass a bytearray into
> other stringlib methods requiring the 'c' format.

Another possibility would be the change the 'c' format so that it accepts any 
object that supports the buffer protocol and whose buffer length is 1.

Attaching two patches: The first allows bytes and bytearray, the second allows 
any object that supports the buffer protocol.

--
keywords: +patch
Added file: http://bugs.python.org/file22756/c_format_bytearray.patch

___
Python tracker 

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



[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-07-16 Thread Eli Bendersky

Eli Bendersky  added the comment:

On one hand, I agree that the situation isn't intuitive. Why should some 
methods of bytearray accept bytearrays, and some shouldn't?

On the other hand, this actually has rather deep implementation reasons. 

Methods like 'translate' are implemented in Objects/bytearrayobject.c

On the other hand, ljust, rjust and center are taken from stringlib. Now, 
stringlib is generic code, and has some strict argument checking. For example, 
in stringlib_ljust:

if (!PyArg_ParseTuple(args, "n|c:ljust", &width, &fillchar))
return NULL;

The 'c' format to PyArg_ParseTuple expects an object that passes PyBytes_Check, 
IOW a bytes object or a subclass thereof. bytearray is not a subclass of bytes, 
hence the problem.

The solution could be global, to allow bytearray fit the 'c' format of 
PyArg_ParseTuple. Then one would also be able to pass a bytearray into other 
stringlib methods requiring the 'c' format.

One way or the other, this is of course doable. A decision has to be made 
though - is the nuisance annoying enough to warrant such an API change?

--

___
Python tracker 

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



[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-06-28 Thread Antoine Pitrou

Changes by Antoine Pitrou :


--
components:  -Documentation

___
Python tracker 

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



[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-06-28 Thread Antoine Pitrou

Antoine Pitrou  added the comment:

I do agree it is a nuisance that it doesn't work with bytearray instances. 
After all, these methods are supposed to be homogeneous, and they are when 
called on a str or bytes object.

--
assignee: docs@python -> 
stage: committed/rejected -> needs patch

___
Python tracker 

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



[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-06-22 Thread Eli Bendersky

Changes by Eli Bendersky :


--
nosy: +eli.bendersky

___
Python tracker 

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



[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-06-22 Thread Terry J. Reedy

Terry J. Reedy  added the comment:

After thinking about this awhile, I see the key sentence of David's reply as 
"The data type of the arguments to the method have no necessary relationship 
with the datatype of the object." While true in general, in it not true with 
respect to corresponing text (string) and byte(array) methods. String 
parameters of strings methods become byte parameters of byte(array) methods. In 
the other hand, I think I agree with David's application to byte versus 
bytearray methods. I might change my mind after further examination of the 
methods in question. But for the present, I would not change the code.

Or would I? Here is a reason not to change. Example:

for byt in (b'abc', bytearray(b'cdef'), b'xye')
  yield byt.rjust(10,b'-')

Making the type of constant args depend on the type of the base object would 
make generic byte/bytearray functions more difficult. We already have this 
problem with writing functions that work with bytes and text in 3.x. It is a 
big nuisance that is only justified by the benefits of not mixing bytes and 
text. I do not think we should extend the nuisance to byte and bytearray 
functions, especially without a strong use case.

I marked this for 'documentation' because I think the doc for some of the str 
methods might be improved and that the reference to them in the bytes/bytearray 
definitely needs more. Doc changes would apply to 3.2 also.

"Bytes and bytearray objects, being “strings of bytes”, have all methods found 
on strings, with the exception ... " 

should be followed by something like. 

"If the string method has a string parameter, the corresponding byte/bytearray 
method has a corresponding byte parameter."

(to match the reported current behavior).

I have not yet looked at doc strings. I did not unmark 'Interpreter core' 
because I have not looked at all of p.u's examples to be sure that I like *all* 
of the current behaviors.

--
assignee:  -> docs@python
components: +Documentation
nosy: +docs@python
resolution: rejected -> 

___
Python tracker 

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



[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-06-21 Thread Petri Lehtinen

Changes by Petri Lehtinen :


--
nosy: +petri.lehtinen

___
Python tracker 

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



[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-06-21 Thread R. David Murray

R. David Murray  added the comment:

All right, let's get some other opinions from people who have actually worked 
with the bytearray and bytes code (and Terry because he cares about APIs).

--
nosy: +haypo, ncoghlan, pitrou, rhettinger, terry.reedy
status: closed -> open

___
Python tracker 

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



[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-06-21 Thread py.user

py.user  added the comment:

> A bytearray is for working with mutable data.  We don't support using > it in 
> all places that the non-mutable data types can be used.

>>> bytearray(b'abcd').strip(bytearray(b'da'))
bytearray(b'bc')
>>>

.translate, .find, .partition, ...

>>> bytearray(b'.').join((bytearray(b'a'), bytearray(b'b')))
bytearray(b'a.b')
>>> bytearray(b'.').join((b'a', b'b'))
bytearray(b'a.b')
>>>

all these methods could use only bytes objects

--

___
Python tracker 

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



[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-06-21 Thread R. David Murray

R. David Murray  added the comment:

A bytearray is for working with mutable data.  We don't support using it in all 
places that the non-mutable data types can be used.  You can code your example 
like this:

   barr.center(len(barr) * 4, bytes([barr[-1]]))

I realize that isn't particularly pretty, but that has more to do with the fact 
that indexing bytes gives you ints in Python 3 than it does with whether or not 
bytearray is accepted.

The data type of the arguments to the method have no necessary relationship 
with the datatype of the object.

You may have more success arguing that the fill character for both bytearray 
and bytes should be allowed to be an int.

I think this whole topic is better addressed in a forum such as python-ideas.  
I agree that the bytes interface is a bit wonky in places, but I think that if 
changes are going to be made a consensus needs to be developed on what changes 
to make.  I believe some conversations about this have already taken place, and 
so far I don't think there are any consensus proposals.

So, I'm going to close this issue.  But please join (or start, if necessary) 
the discussion on this wider topic in the appropriate forum.

--
resolution:  -> rejected
stage:  -> committed/rejected
status: open -> closed

___
Python tracker 

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



[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-06-21 Thread py.user

py.user  added the comment:

all other methods support it and it's right

>>> barr = bytearray(b'abcd*')
>>> barr.center(len(barr) * 4, barr[-1:])
Traceback (most recent call last):
  File "", line 1, in 
TypeError: must be a byte string of length 1, not bytearray
>>> b = b'abcd*'
>>> b.center(len(b) * 4, b[-1:])
b'***abcd*'
>>>

--

___
Python tracker 

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



[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-06-21 Thread R. David Murray

R. David Murray  added the comment:

What's the use case?  I'm inclined to reject this as not needed.

--
nosy: +r.david.murray
type: behavior -> feature request
versions: +Python 3.3 -Python 2.7, Python 3.1

___
Python tracker 

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



[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character

2011-06-20 Thread py.user

Changes by py.user :


--
title: bytearray center, ljust, rjust don't accept a bytearray as the fill 
character -> bytearray methods center, ljust, rjust don't accept a bytearray as 
the fill character

___
Python tracker 

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