Opened 5 years ago

Last modified 5 years ago

#21894 new defect

Do not compare dictionaries which might contain caches — at Version 1

Reported by: saraedum Owned by:
Priority: major Milestone: sage-7.5
Component: pickling Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by saraedum)

The following is a common pattern in implementations of __cmp__ or __eq__:

sage: search_src("cmp\(self.__dict__,")
doctest/control.py:139:        return cmp(self.__dict__,other.__dict__)
doctest/parsing.py:458:        return cmp(self.__dict__, other.__dict__)
doctest/sources.py:152:        return cmp(self.__dict__, other.__dict__)
doctest/util.py:193:        return cmp(self.__dict__, other.__dict__)
sage: search_src("__dict__ == ")
categories/poor_man_map.py:93:        return self.__class__ is other.__class__ and self.__dict__ == other.__dict__
combinat/dlx.py:142:        return self.__dict__ == other.__dict__
combinat/knutson_tao_puzzles.py:586:            return self.__dict__ == other.__dict__
geometry/toric_plotter.py:264:        return type(self) is type(other) and self.__dict__ == other.__dict__
misc/misc.py:1611:        return self.__class__ == other.__class__ and self.__dict__ == other.__dict__
modules/with_basis/morphism.py:334:        return self.__class__ is other.__class__ and parent(self) == parent(other) and self.__dict__ == other.__dict__
modules/with_basis/morphism.py:1474:        return self.__class__ is other.__class__ and self.__dict__ == other.__dict__

This fails as soon as self has a @cached_method:

  • Instances that would be considered equal but have different elements in their cache are not detected as being equal anymore.
  • A restored pickle contains a PickledMethod which is not considered the same as the CachedMethodCaller(NoArgs) in the original object.

Change History (1)

comment:1 Changed 5 years ago by saraedum

  • Description modified (diff)
Note: See TracTickets for help on using tickets.