Skip to content

Verify correctness of LabControlObject's __hash__ and __eq__ methods #494

@charles-cowart

Description

@charles-cowart

As @wasade has pointed out, the base class for most if not all of LabControl's classes is LabControlObject, and this object implements the hash and eq methods.

On review of that code, I'm not convinced the eq method is correct. The hash is hash((self._table, self.id)) whereas eq tests for equality of type() and the id property. This leads to a pathological edge case where two objects can have the same hash but not test equal if an the objects use the same table but have a different subclass. Similarly, this means that two objects can have a different hash, but test equal, if objects of the same type have different _table values.

I don't often implement hash and eq in classes, so I reviewed the code and tested it for myself and I've confirmed this to be true.

At @wasade's request, we should review/test the code and verify whether or not eq's behavior should be changed to match hash or not.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions