Ticket #9556: trac_9556-dynamic_class.patch

File trac_9556-dynamic_class.patch, 3.1 KB (added by mhansen, 9 years ago)
  • sage/functions/other.py

    # HG changeset patch
    # User Mike Hansen <mhansen@gmail.com>
    # Date 1279635661 25200
    # Node ID e17e1cb22c1702ed88543a959deeb92577461c5e
    # Parent  968cddab7aa73ac728d52c01c21aab5000d78aa5
    [mq]: trac_9556-dynamic_class.patch
    
    diff --git a/sage/functions/other.py b/sage/functions/other.py
    a b  
    111111        """
    112112        GinacFunction.__init__(self, "abs", latex_name=r"\mathrm{abs}")
    113113
     114
    114115abs = abs_symbolic = Function_abs()
    115116
    116117class Function_ceil(BuiltinFunction):
     
    280281                return Integer(int(math.ceil(x)))
    281282        return None
    282283
     284
     285    class EvaluationMethods:
     286        def foo_bar(self):
     287            return 4   
     288
    283289ceil = Function_ceil()
    284290
    285291
  • sage/symbolic/expression.pxd

    diff --git a/sage/symbolic/expression.pxd b/sage/symbolic/expression.pxd
    a b  
    1212    cpdef bint is_relational(self)
    1313    cpdef object pyobject(self)
    1414    cpdef Expression _subs_expr(self, expr)
    15    
     15
     16cdef new_Expression_subclass_from_GEx(parent, GEx juice, cls)
    1617cdef Expression new_Expression_from_GEx(parent, GEx juice)
    1718cdef Expression new_Expression_from_pyobject(parent, x)
  • sage/symbolic/expression.pyx

    diff --git a/sage/symbolic/expression.pyx b/sage/symbolic/expression.pyx
    a b  
    75867586    #    return new_Expression_from_GEx(self._parent, g_psi2(self._gobj, x._gobj))
    75877587
    75887588
     7589cdef new_Expression_subclass_from_GEx(parent, GEx juice, cls):
     7590    cdef Expression nex
     7591    result = PY_NEW(cls)
     7592    nex = <Expression>result
     7593    GEx_construct_ex(&nex._gobj, juice)
     7594    nex._parent = parent
     7595    return result
     7596
    75897597
    75907598cdef Expression new_Expression_from_GEx(parent, GEx juice):
    75917599    cdef Expression nex
  • sage/symbolic/function.pyx

    diff --git a/sage/symbolic/function.pyx b/sage/symbolic/function.pyx
    a b  
    1919
    2020
    2121from sage.structure.sage_object cimport SageObject
    22 from expression cimport new_Expression_from_GEx, Expression
     22from expression cimport new_Expression_from_GEx, new_Expression_subclass_from_GEx, Expression
    2323from ring import SR
    2424
    2525from sage.structure.parent cimport Parent
     
    184184        self._serial = g_register_new(opt)
    185185        g_foptions_assign(g_registered_functions().index(self._serial), opt)
    186186
     187    def evaluation_class(self):
     188        if hasattr(self, 'EvaluationMethods'):
     189            from sage.misc.nested_class import nested_pickle
     190            from sage.structure.dynamic_class import dynamic_class
     191
     192            nested_pickle(type(self))
     193            return dynamic_class('Expression_with_evaluation_methods',
     194                                 (self.EvaluationMethods, Expression))
     195        else:
     196            return Expression
     197
    187198    def _eval_default(self, x):
    188199        """
    189200        Default automatic evaluation function.
     
    442453        if not symbolic_input and is_a_numeric(res):
    443454            return py_object_from_numeric(res)
    444455
    445         return new_Expression_from_GEx(SR, res)
     456        return new_Expression_subclass_from_GEx(SR, res, self.evaluation_class())
    446457
    447458    def name(self):
    448459        """