<#20219 pants.util.frozendict.FrozenDict has error...
# github-notifications
c
#20219 pants.util.frozendict.FrozenDict has error prone order-sensitive comparisons Issue created by huonw Describe the bug The
FrozenDict
type is order sensitive, which differs to a normal
dict
. It also gives
False
when comparing to a normal dict. This makes it easy to get unexpected behaviour, and likely leads to unnecessary cache misses. pants/src/python/pants/util/frozendict.py Lines 15 to 21 in </pantsbuild/pants/commit/57d1801c80f8273ca386fba198495a05a45f60ae|57d1801>
Copy code
d1 = {'a': 0, 'b': 1}
d2 = {'b': 1, 'a': 0}
print(d1 == d2) # True
print(FrozenDict(d1) == FrozenDict(d2)) # False

print(FrozenDict(d1) == d1) # False
NB. this seems to apply to all methods that call
tuple(self.items())
or similar:
__eq__
,
__lt__
, `_calculate_hash`/`__hash__`. Pants version
main
OS N/A Additional info This caused half of #20210, see #20220. pantsbuild/pants