diff --git a/brel/brel_fact.py b/brel/brel_fact.py index 5917e913..8f64727d 100644 --- a/brel/brel_fact.py +++ b/brel/brel_fact.py @@ -54,13 +54,9 @@ def __init__( self.__context: Context = context self.__value: str = value - # first class citizens - # TODO think about this. is the id attribute an implementation detail? def _get_id(self) -> str | None: - """ - :returns str|None: The id of the fact. Returns None if the fact does not have an id. - """ - return self.__id + """[DEPRECATED] Use get_id() instead.""" + return self.get_id() def get_id(self) -> str | None: """ @@ -81,6 +77,10 @@ def get_value_as_str(self) -> str: return self.__value def get_value_as_int(self) -> int: + """[DEPRECATED] Use int() instead.""" + return int(self) + + def __int__(self) -> int: """ :returns int: The value of the fact as an int :raises ValueError: If the value of the fact does not resolve to an int @@ -93,6 +93,10 @@ def get_value_as_int(self) -> int: ) def get_value_as_float(self) -> float: + """[DEPRECATED] Use float() instead.""" + return float(self) + + def __float__(self) -> float: """ :returns float: The value of the fact as a float :raises ValueError: If the value of the fact does not resolve to a float @@ -105,6 +109,10 @@ def get_value_as_float(self) -> float: ) def get_value_as_bool(self) -> bool: + """[DEPRECATED] Use bool() instead.""" + return bool(self) + + def __bool__(self) -> bool: """ :returns bool: The value of the fact as a bool :raises ValueError: If the value of the fact does not resolve to a bool @@ -115,7 +123,7 @@ def get_value_as_bool(self) -> bool: return False else: raise ValueError( - f"Fact {self.__id} does not have a bool value. It has value {self.__value}, which does not resolve to a bool" + f"Fact {self.__id} does not have a bool value. It has value {self.__value}, which does not resolve to a bool." ) def get_value(self) -> str: @@ -125,9 +133,15 @@ def get_value(self) -> str: return self.__value def get_precision(self) -> float | None: + """ + :returns Any: The precision of the fact. Only applies to numeric facts. + """ return self.__precision def get_decimals(self) -> float | None: + """ + :returns Any: The decimals property of the fact. Only applies to numeric facts. + """ return self.__decimals def __str__(self) -> str: @@ -202,6 +216,9 @@ def get_characteristic(self, aspect: Aspect) -> ICharacteristic | None: """ return self.__context.get_characteristic(aspect) + def __iter__(self): + return iter(self.convert_to_dict().items()) + def convert_to_dict( self, languages: Optional[List[str]] = None, diff --git a/brel/parsers/XML/networks/xml_extended_link_parser.py b/brel/parsers/XML/networks/xml_extended_link_parser.py index 206089d3..579f7a03 100644 --- a/brel/parsers/XML/networks/xml_extended_link_parser.py +++ b/brel/parsers/XML/networks/xml_extended_link_parser.py @@ -146,7 +146,7 @@ def parse_xml_link( IResource | IReportElement | Fact ] = get_object_from_reference(link_element, context) - if not to_object: + if to_object is None: continue node_arcs = node_to_arcs[label]