#15163: sum() in the console is overshadowed by symbolic_sum() ?
-----------------------------------------------+-------------------------
       Reporter:  darij                        |        Owner:
           Type:  defect                       |       Status:  new
       Priority:  major                        |    Milestone:  sage-5.12
      Component:  misc                         |   Resolution:
       Keywords:  prelude, misc, staticmethod  |    Merged in:
        Authors:                               |    Reviewers:
Report Upstream:  N/A                          |  Work issues:
         Branch:                               |       Commit:
   Dependencies:                               |     Stopgaps:
-----------------------------------------------+-------------------------
Changes (by darij):

 * keywords:  prelude => prelude, misc, staticmethod
 * component:  PLEASE CHANGE => misc


Old description:

> {{{
> sage: c31 = Composition([3,1])
> sage: sum(c31)
> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call
> last)
> <ipython-input-5-cd64b2e19a3e> in <module>()
> ----> 1 sum(c31)
>
> /home/darij/sage-5.11.beta3/local/lib/python2.7/site-
> packages/sage/misc/functional.pyc in symbolic_sum(expression, *args,
> **kwds)
>     652     """
>     653     if hasattr(expression, 'sum'):
> --> 654         return expression.sum(*args, **kwds)
>     655     elif len(args) <= 1:
>     656         return sum(expression, *args)
>
> TypeError: sum() takes exactly 1 argument (0 given)
> }}}
> This should instead return 4 (the sum of the entries of the composition
> c31). This bug appears only interactively; in methods sum() is fine.
>
> The reason why this bug happens in this particular situation is that
> {{{sum}}} is defined as a @staticmethod in the {{{Composition}}} class.
> This method is not supposed to be called on a particular composition (it
> is a @staticmethod after all!), but nevertheless makes
> {{{hasattr(expression, 'sum'):}}} return True when {{{expression}}} is a
> composition. Something should be done about it.

New description:

 {{{
 sage: c31 = Composition([3,1])
 sage: sum(c31)
 ---------------------------------------------------------------------------
 TypeError                                 Traceback (most recent call
 last)
 <ipython-input-5-cd64b2e19a3e> in <module>()
 ----> 1 sum(c31)

 /home/darij/sage-5.11.beta3/local/lib/python2.7/site-
 packages/sage/misc/functional.pyc in symbolic_sum(expression, *args,
 **kwds)
     652     """
     653     if hasattr(expression, 'sum'):
 --> 654         return expression.sum(*args, **kwds)
     655     elif len(args) <= 1:
     656         return sum(expression, *args)

 TypeError: sum() takes exactly 1 argument (0 given)
 }}}
 This should instead return 4 (the sum of the entries of the composition
 c31). This bug appears only interactively; in methods sum() is fine.

 The reason why this bug happens in this particular situation is that
 {{{sum}}} is defined as a @staticmethod in the {{{Composition}}} class.
 This method is not supposed to be called on a particular composition (it
 is a @staticmethod after all!), but nevertheless makes
 {{{hasattr(expression, 'sum')}}} return True when {{{expression}}} is a
 composition. Something should be done about it.

--

--
Ticket URL: <http://trac.sagemath.org/ticket/15163#comment:2>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to