[issue24892] bytes.join() won't take it's own type as the argument

2015-08-19 Thread R. David Murray

R. David Murray added the comment:

In case I wasn't clear: bytes-like object join's argument is *an iterable of 
bytes-like objects*, not an iterable of ints.

--

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



[issue24892] bytes.join() won't take it's own type as the argument

2015-08-19 Thread R. David Murray

R. David Murray added the comment:

I said *enough* motivation.  doing b'x'.join(b'anything') is a very uncommon 
operation (as is the equivalent string case).

There is no parallel to the bytearray constructor, since that constructor does 
not take an iterable of byte-like objects as its input, it takes an iterable of 
ints, as you point out.  There is no parallel to slice assignment, since a 
slice is by definition a bytes like object (that's why using the slice notation 
in the comprehension to the argument of join works).

The inconsistency is entirely a consequence of the fact that if you iterate a 
bytes-like object you get integers.  So, join's behavior is consistent with 
that, and as I said, *I* don't see enough motivation to make a special case 
exception here.  Others may disagree.

--

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



[issue24892] bytes.join() won't take it's own type as the argument

2015-08-19 Thread Brett Cannon

Brett Cannon added the comment:

I agree with David. Concatenating ints to a bytes object doesn't work when you 
directly work with ints and bytes, and so I don't think bytes.join should 
special case it (Zen of Python: Special cases aren't special enough to break 
the rules).

Thanks for the idea anyway, Timothy.

--
nosy: +brett.cannon
resolution:  - rejected
status: open - closed

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



[issue24892] bytes.join() won't take it's own type as the argument

2015-08-18 Thread R. David Murray

R. David Murray added the comment:

I don't think there's enough motivation for making a special case here.

I think this should be rejected; it's working as designed, even if not everyone 
agrees with the design.

--
nosy: +r.david.murray

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



[issue24892] bytes.join() won't take it's own type as the argument

2015-08-18 Thread Timothy Geiser

Timothy Geiser added the comment:

I believe the special case has already been made: iterating over bytes-like 
objects returns ints. Natually, join() should take the same thing. Also, 
constructor bytearray(iterable_of_ints), the mutable-sequence expression 
ba[i:j:k] = t, and the function ba.extend(t) with t as an iterable of ints. 
It's the s.join(t) that's different than all these others.

Again:

 ba = bytearray(b'barbaz')
 ba[0:4:2] = b'ft'
 ba
bytearray(b'fatbaz')
 ba.extend(b'foo')
 ba
bytearray(b'fatbazfoo')
 ba.join(b'not_this_though')
Traceback (most recent call last):
  File pyshell#32, line 1, in module
ba.join(b'not_this_though')
TypeError: sequence item 0: expected a bytes-like object, int found


I'll go ahead argue that it's exactly backwards as is.

--

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



[issue24892] bytes.join() won't take it's own type as the argument

2015-08-18 Thread Timothy Geiser

New submission from Timothy Geiser:

You can't join bytes on another bytes object. (Everything below applies to 
bytearray, as well)


 x = b'foo'
 y = b'barbaz'
 x.join(y)
Traceback (most recent call last):
  File pyshell#2, line 1, in module
x.join(y)
TypeError: sequence item 0: expected a bytes-like object, int found


But this is fine for strings, and gives you exactly what you'd expect


 x = 'foo'
 y = 'barbaz'
 x.join(y)
'bfooafoorfoobfooafooz'
 y.join(x)
'fbarbazobarbazo'


The best work-around I could think of was


 x = b'foo'
 y = b'barbaz'
 x.join(y[i:i+1] for i in range(len(y)))
b'bfooafoorfoobfooafooz'
 y.join(x[i:i+1] for i in range(len(x)))
b'fbarbazobarbazo'


That just doesn't feel nearly pythonic enough, considering that the string 
version works as expected. I'm not even sure what the right solution here is, 
since the problem is that the iterator for a bytes object returns ints, not 
length-one bytes objects. Do we need another signature for the bytes.join 
method that takes byte-like objects and does what I'm describing here?

--
components: Interpreter Core
messages: 248799
nosy: geitda
priority: normal
severity: normal
status: open
title: bytes.join() won't take it's own type as the argument
type: enhancement
versions: Python 3.4

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