Improve enumeration support.

This commit is contained in:
Mike Auty
2019-06-30 14:12:43 +01:00
parent 5e37080c14
commit e503c3667f
3 changed files with 8 additions and 6 deletions
+3 -3
View File
@@ -223,7 +223,7 @@ class SymbolSpaceInterface(collections.abc.Mapping):
"""Look-up a symbol name across all the contained symbol tables"""
@abstractmethod
def get_enumeration(self, enum_name: str) -> Dict[str, Any]:
def get_enumeration(self, enum_name: str) -> objects.Template:
"""Look-up an enumeration across all the contained symbol tables"""
@abstractmethod
@@ -268,14 +268,14 @@ class SymbolTableInterface(BaseSymbolTableInterface, configuration.ConfigurableI
class NativeTableInterface(BaseSymbolTableInterface):
"""Class to distinguish NativeSymbolLists from other symbol lists"""
def get_symbol(self, name: str):
def get_symbol(self, name: str) -> objects.Template:
raise exceptions.SymbolError("NativeTables never hold symbols")
@property
def symbols(self) -> Iterable[str]:
return []
def get_enumeration(self, name: str) -> Dict[str, Any]:
def get_enumeration(self, name: str) -> objects.Template:
raise exceptions.SymbolError("NativeTables never hold enumerations")
@property
+3 -1
View File
@@ -424,8 +424,10 @@ class Enumeration(interfaces.objects.ObjectInterface, int):
inverse_choices[v] = k
return inverse_choices
def lookup(self, value: int) -> str:
def lookup(self, value: int = None) -> str:
"""Looks up an individual value and returns the associated name"""
if value is None:
return self.lookup(self)
if value in self._inverse_choices:
return self._inverse_choices[value]
raise ValueError("The value of the enumeration is outside the possible choices")
+2 -2
View File
@@ -207,10 +207,10 @@ class SymbolSpace(interfaces.symbols.SymbolSpaceInterface):
raise exceptions.SymbolError("Unresolvable Symbol: {}".format(symbol_name))
return retval
def get_enumeration(self, enum_name: str) -> Dict[str, Any]:
def get_enumeration(self, enum_name: str) -> interfaces.objects.Template:
"""Look-up a set of enumeration choices from a specific symbol table"""
retval = self._weak_resolve(SymbolType.ENUM, enum_name)
if not isinstance(retval, dict):
if not isinstance(retval, interfaces.objects.Template):
raise exceptions.SymbolError("Unresolvable Enumeration: {}".format(enum_name))
return retval