Re: restriction on sum: intentional bug?

2009-10-27 Thread Steve
On Oct 17, 8:28 pm, Tim Chase python.l...@tim.thechases.com wrote: Christian Heimes wrote: Alan G Isaac wrote: On 10/16/2009 5:03 PM, Christian Heimes wrote: It's not going to happen. That's a prediction, not a justification. It's not a prediction, it's a statement. It's not going to

Re: restriction on sum: intentional bug?

2009-10-27 Thread Luis Zarrabeitia
On Tuesday 27 October 2009 07:29:46 am Steve wrote: To me the current implementation is blatantly correct. sum is an operation on a list of numeric values, returning a numeric value - this is why we have the seemingly strange .join() rather than [].join () But then, why does sum() accept

Re: restriction on sum: intentional bug?

2009-10-27 Thread Ethan Furman
Steve wrote: On Oct 17, 8:28 pm, Tim Chase python.l...@tim.thechases.com wrote: Christian Heimes wrote: Alan G Isaac wrote: On 10/16/2009 5:03 PM, Christian Heimes wrote: It's not going to happen. That's a prediction, not a justification. It's not a prediction, it's a statement.

Re: restriction on sum: intentional bug?

2009-10-27 Thread Steven D'Aprano
On Tue, 27 Oct 2009 05:29:46 -0700, Steve wrote: To me the current implementation is blatantly correct. sum is an operation on a list of numeric values, returning a numeric value - this is why we have the seemingly strange .join() rather than [].join () That is absolutely wrong. sum() works

Re: restriction on sum: intentional bug?

2009-10-19 Thread ryles
On Oct 16, 6:53 pm, ryles ryle...@gmail.com wrote: Then you probably haven't read through these discussions: sum and strings:http://mail.python.org/pipermail/python-list/2006-August/subject.html summing a bunch of numbers:http://mail.python.org/pipermail/python-dev/2003-April/subj You

Re: restriction on sum: intentional bug?

2009-10-19 Thread Tim Chase
Carl Banks wrote: Consider this thought experiment: class Something(object): def __radd__(self,other): return other + q x = [a,b,c,Something()] If x were passed to .join(), it would throw an exception; but if passed to a sum() without any special casing, it would successfully

Re: restriction on sum: intentional bug?

2009-10-19 Thread Carl Banks
On Oct 19, 3:24 am, Tim Chase python.l...@tim.thechases.com wrote: Carl Banks wrote: Consider this thought experiment: class Something(object):     def __radd__(self,other):         return other + q x = [a,b,c,Something()] If x were passed to .join(), it would throw an exception;

Re: restriction on sum: intentional bug?

2009-10-19 Thread Gabriel Genellina
En Sun, 18 Oct 2009 21:50:55 -0300, Carl Banks pavlovevide...@gmail.com escribió: Consider this thought experiment: class Something(object): def __radd__(self,other): return other + q x = [a,b,c,Something()] If x were passed to .join(), it would throw an exception; but if

Re: restriction on sum: intentional bug?

2009-10-18 Thread Dave Angel
Dieter Maurer wrote: Christian Heimes li...@cheimes.de writes on Fri, 16 Oct 2009 17:58:29 +0200: Alan G Isaac schrieb: I expected this to be fixed in Python 3: sum(['ab','cd'],'') Traceback (most recent call last): File stdin, line 1, in module TypeError:

Re: restriction on sum: intentional bug?

2009-10-18 Thread Ethan Furman
Dave Angel wrote: Dieter Maurer wrote: Christian Heimes li...@cheimes.de writes on Fri, 16 Oct 2009 17:58:29 +0200: Alan G Isaac schrieb: I expected this to be fixed in Python 3: sum(['ab','cd'],'') Traceback (most recent call last): File stdin, line 1, in

Re: restriction on sum: intentional bug?

2009-10-18 Thread Carl Banks
On Oct 18, 4:07 pm, Ethan Furman et...@stoneleaf.us wrote: Dave Angel wrote: Earlier, I would have agreed with you.  I assumed that this could be done invisibly, with the only difference being performance.  But you can't know whether join will do the trick without error till you know that

Re: restriction on sum: intentional bug?

2009-10-18 Thread Steven D'Aprano
On Sun, 18 Oct 2009 19:52:41 -0700, Ethan Furman wrote: This is obviously slow on strings, but mention of that is already in the docs, and profiling will also turn up such bottlenecks. Get the code working first, then optimize, yes? Well, maybe. Premature optimization and all, but

Re: restriction on sum: intentional bug?

2009-10-17 Thread Steven D'Aprano
On Fri, 16 Oct 2009 18:01:41 -0700, Jon Clements wrote: Sum should return a *numeric* result, it has no way to do anything sensible with strings -- that's up to the coder and I think it'd be an error in Python to not raise an error. That's obviously wrong in Python. Mathematically, sum()

Re: restriction on sum: intentional bug?

2009-10-17 Thread Steven D'Aprano
On Fri, 16 Oct 2009 11:06:30 -0700, Jon Clements wrote: For instance, sum(['1', '2', '3']); it's not completely unreasonable for someone to expect a result of 6. This is Python, not Perl -- Python never tries to perform numeric arithmetic on strings. '1'+'2' will return '12' and not 3. It is

Re: restriction on sum: intentional bug?

2009-10-17 Thread Christian Heimes
Alan G Isaac wrote: On 10/16/2009 5:03 PM, Christian Heimes wrote: It's not going to happen. That's a prediction, not a justification. It's not a prediction, it's a statement. It's not going to happend because it violates Guido's gut feeling as well as the Zen of Python. --

Re: restriction on sum: intentional bug?

2009-10-17 Thread Tim Chase
Christian Heimes wrote: Alan G Isaac wrote: On 10/16/2009 5:03 PM, Christian Heimes wrote: It's not going to happen. That's a prediction, not a justification. It's not a prediction, it's a statement. It's not going to happend because it violates Guido's gut feeling as well as the Zen of

Re: restriction on sum: intentional bug?

2009-10-17 Thread Alan G Isaac
On 10/17/2009 7:06 AM, Carl Banks wrote: I'm basically saying here is, by shutting out strings from sum, you don't really lose much in terms of duck typing, because duck typing wouldn't have been that helpful anyway. That boils down to an argument for type checking whenever you cannot imagine

Re: restriction on sum: intentional bug?

2009-10-17 Thread Mark Dickinson
On Oct 17, 9:49 pm, a...@pythoncraft.com (Aahz) wrote: Ahhh, I vaguely remember there being some discussion of this when sum() was introduced -- I think that using InPlaceAdd would have caused bad behavior when the initial list was referred to by multiple names. Thanks for the pointer: I've

Re: restriction on sum: intentional bug?

2009-10-17 Thread Aahz
In article a33fb576-f453-4936-8551-9b999b5e2...@p35g2000yqh.googlegroups.com, Mark Dickinson dicki...@gmail.com wrote: On Oct 17, 9:49=A0pm, a...@pythoncraft.com (Aahz) wrote: Ahhh, I vaguely remember there being some discussion of this when sum() was introduced -- I think that using

Re: restriction on sum: intentional bug?

2009-10-17 Thread Terry Reedy
Alan G Isaac wrote: On 10/16/2009 8:16 PM, Terry Reedy wrote: The fact that two or three people who agree on something agree on the thing that they agree on confirms nothing. If you disagree with this, I think *you* are being silly. One could just as well argue that summing anything but

Re: restriction on sum: intentional bug?

2009-10-17 Thread MRAB
Carl Banks wrote: On Oct 17, 2:22 pm, Alan G Isaac alan.is...@gmail.com wrote: On 10/17/2009 7:06 AM, Carl Banks wrote: I'm basically saying here is, by shutting out strings from sum, you don't really lose much in terms of duck typing, because duck typing wouldn't have been that helpful

Re: restriction on sum: intentional bug?

2009-10-17 Thread Alan G Isaac
On 10/16/2009 8:16 PM, Terry Reedy wrote: The fact that two or three people who agree on something agree on the thing that they agree on confirms nothing. On 10/17/2009 7:03 PM, Terry Reedy wrote: If you disagree with this, I think *you* are being silly. Well, ... Alan G Isaac wrote: Of

Re: restriction on sum: intentional bug?

2009-10-17 Thread Steven D'Aprano
On Sat, 17 Oct 2009 07:27:44 -0700, Aahz wrote: (For the record, summing lists is O(N**2), and unlike strings, there's no optimization in CPython to avoid the slow behaviour.) Are you sure? Not 100% -- I haven't read the CPython source code. But I have done timing tests for repeated

Re: restriction on sum: intentional bug?

2009-10-17 Thread Dieter Maurer
Christian Heimes li...@cheimes.de writes on Fri, 16 Oct 2009 17:58:29 +0200: Alan G Isaac schrieb: I expected this to be fixed in Python 3: sum(['ab','cd'],'') Traceback (most recent call last): File stdin, line 1, in module TypeError: sum() can't sum strings [use ''.join(seq)

Re: restriction on sum: intentional bug?

2009-10-16 Thread Alan G Isaac
Alan G Isaac schrieb: I expected this to be fixed in Python 3: sum(['ab','cd'],'') Traceback (most recent call last): File stdin, line 1, inmodule TypeError: sum() can't sum strings [use ''.join(seq) instead] Of course it is not a good way to join strings, but it should work, should it

Re: restriction on sum: intentional bug?

2009-10-16 Thread Peter Otten
Alan G Isaac wrote: I expected this to be fixed in Python 3: sum(['ab','cd'],'') Traceback (most recent call last): File stdin, line 1, in module TypeError: sum() can't sum strings [use ''.join(seq) instead] Of course it is not a good way to join strings, but it should work, should

Re: restriction on sum: intentional bug?

2009-10-16 Thread MRAB
Stephen Hansen wrote: On Fri, Oct 16, 2009 at 8:39 AM, Alan G Isaac alan.is...@gmail.com mailto:alan.is...@gmail.com wrote: I expected this to be fixed in Python 3: sum(['ab','cd'],'') Traceback (most recent call last): File stdin, line 1, in module

Re: restriction on sum: intentional bug?

2009-10-16 Thread Tim Chase
Stephen Hansen wrote: Why doesn't duck typing apply to `sum`? Because it would be so hideously slow and inefficient that it'd be way too easy a way for people to program something they think should work fine but really doesn't... alternatively, the function would have to do two /completely/

Re: restriction on sum: intentional bug?

2009-10-16 Thread Benjamin Peterson
MRAB python at mrabarnett.plus.com writes: It checks to see whether you're trying to sum strings, so it's already treating them as a special case. Why can't it just use str.join internally instead in that case instead of raising an exception? Because that violates explicit is better than

Re: restriction on sum: intentional bug?

2009-10-16 Thread Benjamin Peterson
Alan G Isaac alan.isaac at gmail.com writes: So of course join is better, as originally noted, but that does not constitute a reason to intentionally violate duck typing. As Stephen pointed out, duck typing is not an absolute. -- http://mail.python.org/mailman/listinfo/python-list

Re: restriction on sum: intentional bug?

2009-10-16 Thread Stephen Hansen
On Fri, Oct 16, 2009 at 9:59 AM, Tim Chase python.l...@tim.thechases.comwrote: Stephen Hansen wrote: Why doesn't duck typing apply to `sum`? Because it would be so hideously slow and inefficient that it'd be way too easy a way for people to program something they think should work fine but

Re: restriction on sum: intentional bug?

2009-10-16 Thread Jon Clements
On Oct 16, 5:59 pm, Tim Chase python.l...@tim.thechases.com wrote: Stephen Hansen wrote: Why doesn't duck typing apply to `sum`? Because it would be so hideously slow and inefficient that it'd be way too easy a way for people to program something they think should work fine but really

Re: restriction on sum: intentional bug?

2009-10-16 Thread Ethan Furman
Jon Clements wrote: On Oct 16, 5:59 pm, Tim Chase python.l...@tim.thechases.com wrote: Stephen Hansen wrote: Why doesn't duck typing apply to `sum`? Because it would be so hideously slow and inefficient that it'd be way too easy a way for people to program something they think should work

Re: restriction on sum: intentional bug?

2009-10-16 Thread Tim Chase
Stephen Hansen wrote: There really is just a right way verses a wrong way to join strings together; using + is always the wrong way. Sometimes that level of 'wrong' is so tiny that no one cares, like if you are using it to join together two small strings. But when joining together a sequence of

Re: restriction on sum: intentional bug?

2009-10-16 Thread Alan G Isaac
On 10/16/2009 3:40 PM, Tim Chase wrote: What's always wrong is giving me an *error* when the semantics are perfectly valid. Exactly. Which is why I expected this to be fixed in Python 3. Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

Re: restriction on sum: intentional bug?

2009-10-16 Thread Christian Heimes
Alan G Isaac schrieb: On 10/16/2009 3:40 PM, Tim Chase wrote: What's always wrong is giving me an *error* when the semantics are perfectly valid. Exactly. Which is why I expected this to be fixed in Python 3. It's not going to happen. Christian --

Re: restriction on sum: intentional bug?

2009-10-16 Thread Alan G Isaac
On 10/16/2009 5:03 PM, Christian Heimes wrote: It's not going to happen. That's a prediction, not a justification. As Tim explained in detail, and as Peter explained with brevity, whether it will happen or not, it should happen. This conversation has confirmed that current behavior is a

Re: restriction on sum: intentional bug?

2009-10-16 Thread ryles
On Oct 16, 11:39 am, Alan G Isaac alan.is...@gmail.com wrote: I expected this to be fixed in Python 3: sum(['ab','cd'],'') Traceback (most recent call last):    File stdin, line 1, in module TypeError: sum() can't sum strings [use ''.join(seq) instead] Then you probably haven't read

Re: restriction on sum: intentional bug?

2009-10-16 Thread Carl Banks
On Oct 16, 9:59 am, Tim Chase python.l...@tim.thechases.com wrote: So I agree with Alan Peter that this creates an unfortunate language wart among (as Peter aptly puts it) consenting adults. Perhaps, BUT... If, say, you were to accept that Python is going to guard against a small number of

Re: restriction on sum: intentional bug?

2009-10-16 Thread Carl Banks
On Oct 16, 12:40 pm, Tim Chase python.l...@tim.thechases.com wrote: Then I'm fine with sum() being smart enough to recognize this horrid case and do the right thing by returning ''.join() instead. You don't want Python to get into this business. Trust me. Just don't go there. If you want

Re: restriction on sum: intentional bug?

2009-10-16 Thread Carl Banks
On Oct 16, 8:39 am, Alan G Isaac alan.is...@gmail.com wrote: I expected this to be fixed in Python 3: A word of advice: the Python maintainers don't regard anything that behaves as it is documented to as a bug, no matter how wrong it seems. This is taken a lot more seriously than you would

Re: restriction on sum: intentional bug?

2009-10-16 Thread Terry Reedy
Alan G Isaac wrote: As Tim explained in detail, and as Peter explained with brevity, whether it will happen or not, it should happen. This conversation has confirmed that current behavior is a wart: an error is raised despite correct semantics. Ugly! The fact that two or three people who

Re: restriction on sum: intentional bug?

2009-10-16 Thread Jon Clements
On Oct 17, 1:16 am, Terry Reedy tjre...@udel.edu wrote: Alan G Isaac wrote: As Tim explained in detail, and as Peter explained with brevity, whether it will happen or not, it should happen.  This conversation has confirmed that current behavior is a wart: an error is raised despite

Re: restriction on sum: intentional bug?

2009-10-16 Thread Alan G Isaac
On 10/16/2009 8:16 PM, Terry Reedy wrote: The fact that two or three people who agree on something agree on the thing that they agree on confirms nothing. One could just as well argue that summing anything but numbers is semantically incoherent, not correct. Certainly, my dictionary points in

Re: restriction on sum: intentional bug?

2009-10-16 Thread Alan G Isaac
Alan G Isaacalan.isaacat gmail.com writes: So of course join is better, as originally noted, but that does not constitute a reason to intentionally violate duck typing. On 10/16/2009 1:03 PM, Benjamin Peterson wrote: As Stephen pointed out, duck typing is not an absolute. I do not