[Sqlalchemy-tickets] Issue #3265: _AssociationSet has odd __eq__ behaviour (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
|
From: Saif H. <iss...@bi...> - 2014-12-04 22:31:32
|
New issue 3265: _AssociationSet has odd __eq__ behaviour https://bitbucket.org/zzzeek/sqlalchemy/issue/3265/_associationset-has-odd-__eq__-behaviour Saif Hakim: If I have association proxies for sets, I noticed that `__eq__` does't behave as expected. Namely, two empty association sets are not considered equal, nor is an association set equal to itself. This results from the implementation: ``` def __eq__(self, other): return set(self) == other ``` If we reverse the terms, and instead use: ``` def __eq__(self, other): return other == set(self) ``` Then the comparison of `set_a == set_b`, will end up doing `set_a.__eq__(set_b)` --> `set_b.__eq__(set(a))` --> `set(a).__eq__(set(b))` which seems to be the desired behavior. This same fix would be applied to most, if not all, of the comparison operators. Though, `set() == empty_association_set` will still be False... but there isn't much you can do about that. See the attached example using the User, Keyword example of AssociationProxy. |