Unexpected Inheritance Problem

Richard Damon Richard at Damon-Family.org
Thu May 20 00:00:40 EDT 2021


Given the following definition of classes, I am getting an unexpected
error of :

TypeError:  __init__() missing 2 required keyword-only arguments:
'idcode' and 'tag'

On the call to create a GedcomHead in the call to GedcomHead() in
Gedcom0Tag.add()

Code:


class GedcomTag:
    """Represents a Level of a Gedcom file"""

    def __init__(self, parent: 'GedcomTag', level: int, tag: str,
payload: Optional[str]):
        pass


class Gedcom0Tag(GedcomTag):
    """Represents a Level 0 Tag of a GEDCOM file"""

    def __init__(self, *, parent, idcode: Optional[str], tag: str):
        super().__init__(parent=parent, level=0, tag=tag, payload=idcode)

    @classmethod
    def add(cls, *, parent, tag: str, payload: str, level=0):
        """Add Tag based on text"""
        if tag == 'HEAD':
            data = GedcomHead(parent=parent)
        elif tag == 'TRLR':
            data = GedcomTRLR(parent=parent)
        else:
            data = Gedcom0Tag(idcode=tag, tag=payload, parent=parent)
        return data

class GedcomHead(Gedcom0Tag):
    """GEDCOM 0 HEAD tag"""
    def ___init___(self, *, parent):
        super().__init__(parent=parent, idcode=None, tag="HEAD")

Gedcom0Tag.add(parent, 'Head', '')

Note: GedcomHead.__init__() doesn't have these parameters, somehow it seems be requiring the parameters for the __init__ call of the base class too, even though there is a call to it through the super().__init__()

Is this expected? 
Can derived classes not provide values for parameters to construct the base classes?
Is there something funny because I am making the call from a member of that base class?




-- 
Richard Damon



More information about the Python-list mailing list