Hi Gonzalo,

On 7 Jun., 21:25, Gonzalo Tornaria <[email protected]> wrote:
> What is the base class that one is supposed to use instead of ParentWithBase?

I think it is Parent. The Parent.__init__ accepts an argument base.

Here is a small example:

from sage.structure.parent import Parent
from sage.structure.element import Element

class MyElement(Element):
    def __init__(self,n,parent):
        Element.__init__(self,parent)
        self.n = n
    def _repr_(self):
        return repr(self.n)

class MyParent(Parent):
    Element = MyElement
    def __init__(self,B):
        from sage.all import Sets
        Parent.__init__(self,base=B, category=Sets())
    def _repr_(self):
        return "Parent over %s"%self.base()

And if you attach that code, then you  can do

sage: P = MyParent(QQ)
sage: P
Parent over Rational Field
sage: P.base()
Rational Field

As you see, the base() method exists and works correctly.

As for element constructor, in my minimal example I just provide a
class as an attribute called "Element" to the parent class. Then, an
element constructor is correctly inferred (that's one reason to
initialise the category of the parent):

sage: P(3)
3
sage: type(_)
<class '__main__.MyParent_with_category.element_class'>
sage: isinstance(P(3),MyElement)
True
sage: P._element_constructor_??
Type:           instancemethod
...
        def _element_constructor_from_element_class(self, *args,
**keywords):
            """
            The default constructor for elements of this parent

I hope that answers your question.

Best regards,
Simon

-- 
To post to this group, send an email to [email protected]
To unsubscribe from this group, send an email to 
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to