def __add__(self, other):
        """Add structures to get a new structure that is common to both.

        The returned structure is a newly created structure that reflects the
        similarities and differences between the two structures added.
        """

        key_guaranteed = self.key_guaranteed and other.key_guaranteed
        val_guaranteed = self.val_guaranteed and other.val_guaranteed

        if self.type_ is other.type_:
            new = Structure(None, key=self.key)
            new.type_ = self.type_
            new.key_guaranteed = key_guaranteed
            new.val_guaranteed = val_guaranteed

            if self.is_list and other.is_list:
                listchild = self.children[0] + other.children[0]
                listchild.parent = new
                new.children.append(listchild)
                return new
            elif self.is_tuple and other.is_tuple:
                zipped = zip_longest(self.children, other.children)
                for schild, ochild in zipped:
                    if schild is None:
                        newchild = ochild.copy(new)
                        newchild.val_guaranteed = False
                        new.children.append(newchild)
                    elif ochild is None:
                        newchild = schild.copy(new)
                        newchild.val_guaranteed = False
                        new.children.append(newchild)
                    else:
                        newchild = schild + ochild
                        newchild.parent = new
                        new.children.append(newchild)
                return new
            elif self.is_dict and other.is_dict:
                keysdict = defaultdict(lambda: [None, None])
                for child in self.children:
                    keysdict[child.key][0] = child
                for child in other.children:
                    keysdict[child.key][1] = child
                for c1, c2 in keysdict.values():
                    if c1 is None:
                        newchild = c2.copy(new)
                        newchild.key_guaranteed = False
                    elif c2 is None:
                        newchild = c1.copy(new)
                        newchild.key_guaranteed = False
                    else:
                        newchild = c1 + c2
                        newchild.parent = new
                    new.children.append(newchild)
                new.children.sort(key=lambda child: child.key)
                return new
            else:
                return new
        else:
            if self.type_ is _EMPTY_TYPE:
                new = other.copy()
            elif other.type_ is _EMPTY_TYPE:
                new = self.copy()
            elif self.type_ is _NONE_TYPE:
                new = other.copy()
                new.key_guaranteed = key_guaranteed
                new.val_guaranteed = False
            elif other.type_ is _NONE_TYPE:
                new = self.copy()
                new.key_guaranteed = key_guaranteed
                new.val_guaranteed = False
            else:
                new = Structure(None, key=self.key)
                new.key_guaranteed = key_guaranteed
                new.val_guaranteed = val_guaranteed
                new.type_ = _MIXED_TYPE
            return new
def __add__ ( self , other ) : key_guaranteed = self . key_guaranteed and other . key_guaranteed val_guaranteed = self . val_guaranteed and other . val_guaranteed if self . type_ is other . type_ : new = Structure ( None , key = self . key ) new . type_ = self . type_ new . key_guaranteed = key_guaranteed new . val_guaranteed = val_guaranteed if self . is_list and other . is_list : listchild = self . children [ 0 ] + other . children [ 0 ] listchild . parent = new new . children . append ( listchild ) return new elif self . is_tuple and other . is_tuple : zipped = zip_longest ( self . children , other . children ) for schild , ochild in zipped : if schild is None : newchild = ochild . copy ( new ) newchild . val_guaranteed = False new . children . append ( newchild ) elif ochild is None : newchild = schild . copy ( new ) newchild . val_guaranteed = False new . children . append ( newchild ) else : newchild = schild + ochild newchild . parent = new new . children . append ( newchild ) return new elif self . is_dict and other . is_dict : keysdict = defaultdict ( lambda : [ None , None ] ) for child in self . children : keysdict [ child . key ] [ 0 ] = child for child in other . children : keysdict [ child . key ] [ 1 ] = child for c1 , c2 in keysdict . values ( ) : if c1 is None : newchild = c2 . copy ( new ) newchild . key_guaranteed = False elif c2 is None : newchild = c1 . copy ( new ) newchild . key_guaranteed = False else : newchild = c1 + c2 newchild . parent = new new . children . append ( newchild ) new . children . sort ( key = lambda child : child . key ) return new else : return new else : if self . type_ is _EMPTY_TYPE : new = other . copy ( ) elif other . type_ is _EMPTY_TYPE : new = self . copy ( ) elif self . type_ is _NONE_TYPE : new = other . copy ( ) new . key_guaranteed = key_guaranteed new . val_guaranteed = False elif other . type_ is _NONE_TYPE : new = self . copy ( ) new . key_guaranteed = key_guaranteed new . val_guaranteed = False else : new = Structure ( None , key = self . key ) new . key_guaranteed = key_guaranteed new . val_guaranteed = val_guaranteed new . type_ = _MIXED_TYPE return new
Add structures to get a new structure that is common to both.

        The returned structure is a newly created structure that reflects the
        similarities and differences between the two structures added.