@@ -15,10 +15,10 @@ class ld_list(ld_container):
1515 def __init__ (self , data , * , parent = None , key = None , index = None , context = None ):
1616 """ Create a new ld_list.py container.
1717
18- # FIXME: there is no parameter container
18+ # FIXME: #439 there is no parameter container
1919 :param container: The container type for this list.
2020 """
21- # FIXME: A set container does not contain "@set" in the expected data format (expanded json ld)
21+ # FIXME: #439 A set container does not contain "@set" in the expected data format (expanded json ld)
2222 # Instead it is just a list of dicts and therefor would raise a ValueError here (and fail ld_list.is_ld_list)
2323
2424 super ().__init__ (data , parent = parent , key = key , index = index , context = context )
@@ -42,7 +42,7 @@ def __getitem__(self, index):
4242 return item
4343
4444 def __setitem__ (self , index , value ):
45- # FIXME: what should your_ld_list[index] = [{"@type": "foo", "name": "bar"}] mean?
45+ # FIXME: #439 what should your_ld_list[index] = [{"@type": "foo", "name": "bar"}] mean?
4646 # set your_ld_list[index] to the dict {"@type": "foo", "name": "bar"} given in expanded form or
4747 # set your_ld_list[index] to the list [{"@type": "foo", "name": "bar"}] given in non expanded form or
4848 # set your_ld_list[index] to the set [{"@type": "foo", "name": "bar"}] given in expanded form
@@ -52,7 +52,7 @@ def __setitem__(self, index, value):
5252 # This is relevent because nested sets get unnested when being expanded and lists not.
5353 # Moreover a set inside a list gets automaticaly converted to a list when expanded)
5454
55- # FIXME: what happens when a ld_list is put inside another also depends on their container types
55+ # FIXME: #439 what happens when a ld_list is put inside another also depends on their container types
5656
5757 if not isinstance (index , slice ):
5858 self .item_list [index ] = val [0 ] if isinstance (val := self ._to_expanded_json (self .key , value ), list ) else val
@@ -74,6 +74,24 @@ def __iter__(self):
7474 item .index = index
7575 yield item
7676
77+ def __contains__ (self , value ):
78+ expanded_value = val [0 ] if isinstance (val := self ._to_expanded_json (self .key , value ), list ) else val
79+ return expanded_value in self .item_list
80+
81+ def __eq__ (self , other ):
82+ if isinstance (other , ld_list ):
83+ # FIXME: #439 When are ld_lists equal?
84+ return self .item_list == other .item_list and self .container == other .container
85+ if isinstance (other , list ):
86+ return self .item_list == self ._to_expanded_json (self .key , other )[0 ]["@list" ]
87+ return NotImplemented
88+
89+ def __ne__ (self , other ):
90+ x = self .__eq__ (other )
91+ if x is NotImplemented :
92+ return NotImplemented
93+ return not x
94+
7795 def append (self , value ):
7896 ld_value = self ._to_expanded_json (self .key , value )
7997 self .item_list .extend (ld_value )
@@ -90,12 +108,12 @@ def to_python(self):
90108
91109 @classmethod
92110 def is_ld_list (cls , ld_value ):
93- # FIXME: every python list that contains at least one dict can be considerd a set in expanded json form
111+ # FIXME: #439 every python list that contains at least one dict can be considerd a set in expanded json form
94112 return cls .is_ld_node (ld_value ) and cls .is_container (ld_value [0 ])
95113
96114 @classmethod
97115 def is_container (cls , value ):
98- # FIXME: "@set" will never be inside a dictionary of an expanded json ld object
116+ # FIXME: #439 "@set" will never be inside a dictionary of an expanded json ld object
99117 return (
100118 isinstance (value , dict )
101119 and len ([1 for ct in cls .container_types if isinstance (value .get (ct , None ), list )]) == 1
0 commit comments