util: allow accessing NamedInts by readable name

This commit is contained in:
Peter F. Patel-Schneider 2020-11-02 20:21:14 -05:00
parent 4da7feec3b
commit 02a7d8cadd
1 changed files with 2 additions and 1 deletions

View File

@ -153,6 +153,7 @@ class NamedInts(object):
elif is_string(index):
if index in self.__dict__:
return self.__dict__[index]
return (next((x for x in self._values if str(x) == index), None))
elif isinstance(index, slice):
if index.start is None and index.stop is None:
@ -203,7 +204,7 @@ class NamedInts(object):
if isinstance(value, int):
return value in self._indexed
elif is_string(value):
return value in self.__dict__
return value in self.__dict__ or value in self._values
def __iter__(self):
for v in self._values: