On Wed, Oct 31, 2012 at 05:39:06PM -0700, Andrew Mathas wrote:
>    I think that the problem is that when sage creates a class then it creates
>    copies in memory of all of the (inherited) methods of the class.

Not exactly. What happens is that, for P a parent (here P=Tableaux),
the class P.element_class is not P.Element (here Tableau) but a
subclass of it, constructed to let a tableau inherit code from
categories:

    sage: T = Tableaux()
    sage: T.Element
    <class 'sage.combinat.tableau.Tableau'>
    sage: T.element_class
    <class 'sage.combinat.tableau.Tableaux_all_with_category.element_class'>
    sage: T.element_class.__bases__
    (<class 'sage.combinat.tableau.Tableau'>, <class 
'sage.categories.sets_cat.Sets.element_class'>)

As a consequence:

    sage: issubclass(SemistandardTableaux().element_class, 
Tableaux().element_class)
    False

even though:

    sage: issubclass(SemistandardTableaux().Element, Tableaux().Element)
    True

So what you want to do is not to insert your method in the class
of the tableau, but in its superclass (i.e. Tableau):

    sage: t = Tableau([[2]])
    sage: s = SemistandardTableau([[2]])
    sage: t.__class__.__base__.foo = lambda self: 1
    sage: t.foo()
    1
    sage: s.foo()
    1

Cheers,
                                Nicolas
--
Nicolas M. ThiƩry "Isil" <nthi...@users.sf.net>
http://Nicolas.Thiery.name/

-- 
You received this message because you are subscribed to the Google Groups 
"sage-combinat-devel" group.
To post to this group, send email to sage-combinat-devel@googlegroups.com.
To unsubscribe from this group, send email to 
sage-combinat-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sage-combinat-devel?hl=en.

Reply via email to