receiver: fix contains for NamedInts and eliminate use of has_element

This commit is contained in:
Peter F. Patel-Schneider 2022-01-24 13:49:08 -05:00
parent f6b25a9685
commit 7a9f9972a6
2 changed files with 4 additions and 7 deletions

View File

@ -211,7 +211,9 @@ class NamedInts:
self._indexed[int(value)] = value self._indexed[int(value)] = value
def __contains__(self, value): def __contains__(self, value):
if isinstance(value, int): if isinstance(value, NamedInt):
return self[value] == value
elif isinstance(value, int):
return value in self._indexed return value in self._indexed
elif is_string(value): elif is_string(value):
return value in self.__dict__ or value in self._values return value in self.__dict__ or value in self._values
@ -228,9 +230,6 @@ class NamedInts:
def __or__(self, other): def __or__(self, other):
return NamedInts(**self.__dict__, **other.__dict__) return NamedInts(**self.__dict__, **other.__dict__)
def has_element(self, value):
return self[value] == value
class UnsortedNamedInts(NamedInts): class UnsortedNamedInts(NamedInts):
def _sort_values(self): def _sort_values(self):

View File

@ -898,9 +898,7 @@ class SmartComboBox(Gtk.ComboBox):
values = self._all_values[:] values = self._all_values[:]
if include_new and only is not None: if include_new and only is not None:
values += [v for v in only if v not in self._value_to_idx] values += [v for v in only if v not in self._value_to_idx]
self.set_all_values( self.set_all_values(values, (lambda v: only is None or (v in only)))
values, (lambda v: only is None or (only.has_element(v) if isinstance(only, NamedInts) else (v in only)))
)
@dataclass @dataclass