Closed Fliens closed 7 months ago
ua.DataValue() or ua.Variant() are both python dataclasses.
DataValue has no __eq__
method!
https://github.com/FreeOpcUa/opcua-asyncio/blob/d4d4c84366dea6bc0ede632fff0821b00f85d8eb/asyncua/ua/uatypes.py#L1069
Variant has a __eq__
method
https://github.com/FreeOpcUa/opcua-asyncio/blob/d4d4c84366dea6bc0ede632fff0821b00f85d8eb/asyncua/ua/uatypes.py#L911
def __eq__(self, other):
if (
isinstance(other, Variant)
and self.VariantType == other.VariantType
and self.Value == other.Value
):
return True
return False
so comparing variant1 == variant2 should work as in python docs described. https://docs.python.org/3/reference/datamodel.html#object.__eq__
Ahh great thank you for the response this answers my question :)
Hi as the title says, I want to compare the values of two nodes.
I want to make sure that python does nothing unintendet in the background with the node datatypes. For example when comparing nodes with different types of int: int16, int32, int64, Uint16, Uint32, Uint64.
I'm worried that the python "==" could create false positive or general negative results when comparing plain values of nodes
Example
Is there a better way to compare two ua.DataValue() or ua.Variant() that keeps the datatype of the value in mind? Instances of these classes can't be compared directly since they also have a timestamp that might not be important for comparing their values.
Sth like this: