File tree 2 files changed +14
-0
lines changed
2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -850,6 +850,12 @@ def __getattr__(self, name):
850
850
f"may only be accessed by indexing" )
851
851
return item
852
852
853
+ def __len__ (self ):
854
+ if not isinstance (self .__layout , ArrayLayout ):
855
+ raise TypeError (
856
+ f"`len()` can only be used on views of array layout, not { self .__layout !r} " )
857
+ return self .__layout .length
858
+
853
859
def __eq__ (self , other ):
854
860
if isinstance (other , View ) and self .__layout == other .__layout :
855
861
return self .__target == other .__target
Original file line number Diff line number Diff line change @@ -763,6 +763,14 @@ def test_eq(self):
763
763
r"with the same layout, not .*$" ):
764
764
s1 != Const (0 , 2 )
765
765
766
+ def test_len (self ):
767
+ s1 = Signal (data .StructLayout ({"a" : unsigned (2 )}))
768
+ with self .assertRaisesRegex (TypeError ,
769
+ r"^`len\(\)` can only be used on views of array layout, not StructLayout.*$" ):
770
+ len (s1 )
771
+ s2 = Signal (data .ArrayLayout (2 , 3 ))
772
+ self .assertEqual (len (s2 ), 3 )
773
+
766
774
def test_operator (self ):
767
775
s1 = Signal (data .StructLayout ({"a" : unsigned (2 )}))
768
776
s2 = Signal (unsigned (2 ))
You can’t perform that action at this time.
0 commit comments