from hwt.synthesizer.interfaceLevel.mainBases import InterfaceBase


class HObjList(list):
    """
    Regular list with some interface/unit methods delegated on items.
    
    Main purpose of this class it let :class:`hwt.synthesizer.PropDeclrCollector.PropDeclrCollector`
    know that this is not an regular python array and that items should be registered as HW objects.
    
    :note: :class:`hwt.synthesizer.PropDeclrCollector.PropDeclrCollector` is used by
        :class:`hwt.synthesizer.interface.Interface` and :class:`hwt.synthesizer.unit.Unit`
    """
    def __init__(self, *args, **kwargs):
        list.__init__(self, *args, **kwargs)
        self._name = None
        self._parent = None

    def _m(self):
        for item in self:
            item._m()
        return self

    def _getFullName(self):
        """get all name hierarchy separated by '.' """
        name = ""
        tmp = self
        while isinstance(tmp, (InterfaceBase, HObjList)):
            if hasattr(tmp, "_name"):
                n = tmp._name
            else:
                n = ''
            if name == '':
                name = n
            else:
                name = n + '.' + name
            if hasattr(tmp, "_parent"):
                tmp = tmp._parent
            else:
                tmp = None
        return name
    
    def _make_association(self, *args, **kwargs):
        """
        Delegate _make_association on items
        
        :note: doc in :func:`~hwt.synthesizer.interfaceLevel.propDeclCollector._make_association`
        """
        for o in self:
            o._make_association(*args, **kwargs)
    
    def _updateParamsFrom(self, *args, **kwargs):
        """
        :note: doc in :func:`~hwt.synthesizer.interfaceLevel.propDeclCollector._updateParamsFrom`
        """
        for o in self:
            o._updateParamsFrom(*args, **kwargs)
    
    def __call__(self, other):
        if not isinstance(other, HObjList) or len(self) != len(other):
            return TypeError()
        
        statements = []
        for a, b in zip(self, other):
            statements += a(b)
        
        return statements
@@ -162,21 +162,17 @@
  items.%0A
-    
 %0A
+
     Main
@@ -365,21 +365,17 @@
 bjects.%0A
-    
 %0A
+
     :not
@@ -547,24 +547,25 @@
 it%60%0A    %22%22%22%0A
+%0A
     def __in
@@ -1314,21 +1314,17 @@
 rn name%0A
-    
 %0A
+
     def 
@@ -1421,25 +1421,17 @@
 n items%0A
-        
 %0A
+
         
@@ -1596,37 +1596,33 @@
 args, **kwargs)%0A
-    
 %0A
+
     def _updateP
@@ -1849,21 +1849,17 @@
 kwargs)%0A
-    
 %0A
+
     def 
@@ -1918,85 +1918,209 @@
 er, 
-HObjList) or len(self) != len(other):%0A            return TypeError()%0A        
+list):%0A            raise TypeError(other)%0A        if len(self) != len(other):%0A            raise ValueError(%22Different number of interfaces in list%22,%0A                             len(self), len(other))%0A
 %0A   
@@ -2209,24 +2209,16 @@
 += a(b)%0A
-        
 %0A       
@@ -2227,16 +2227,17 @@
 eturn statements
+%0A

fix HObjList type errors