implement __hash__ in a way that preserves C++ object identity #29

Closed
opened 2024-03-09 19:01:55 +00:00 by john · 1 comment
Owner

Notes say:
34 feat: All python objects that wrap C++ classes should return the "data" pointer address as a hash, so that "is" operator will work on UI objects or collections generated as different Python objects

  • PyUIDrawable derived class implementations pretty universally use data as a std::shared_ptr<UIDerivedSomethingOrOther>. The actual pointer address inside that shared pointer is the object, and it's how live changes are made.
  • But the PyTYPE_HEAD or whatever holds the Python object info can be duplicated - multiple Python objects can hold shared pointers to the same C++ object. Totally intentional.
  • If Python objects point to the same C++ object, a is b should return True.
Notes say: 34 feat: All python objects that wrap C++ classes should return the "data" pointer address as a hash, so that "is" operator will work on UI objects or collections generated as different Python objects * PyUIDrawable derived class implementations pretty universally use `data` as a `std::shared_ptr<UIDerivedSomethingOrOther>`. The actual pointer address inside that shared pointer *is* the object, and it's how live changes are made. * But the `PyTYPE_HEAD` or whatever holds the Python object info can be duplicated - multiple Python objects can hold shared pointers to the same C++ object. Totally intentional. * If Python objects point to the same C++ object, `a is b` should return `True`.
john added the
Tiny Feature
label 2024-03-09 19:02:10 +00:00
john added this to the Fun, Convenient McRogueFace Objects project 2024-03-13 14:49:53 +00:00
Author
Owner

wontfix / the current usage of hash is probably incorrect and should be deprecated. Hashable object should be immutable. So the mcrf data containers probably should not have this value.

wontfix / the current usage of hash is probably incorrect and should be deprecated. Hashable object should be immutable. So the mcrf data containers probably should not have this value.
john closed this issue 2024-04-20 18:23:16 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: john/McRogueFace#29
No description provided.