-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
BUG : don't use mutable objects as dictionary keys #2927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -554,7 +554,8 @@ def _convert_path(self, path, transform, clip=False, simplify=None): | |||
return ps | |||
|
|||
def _get_clip_path(self, clippath, clippath_transform): | |||
id = self._clip_paths.get((clippath, clippath_transform)) | |||
key = (clippath, clippath_transform.get_matrix().tostring) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be tostring()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, fixed, squashed and forced.
@@ -554,7 +554,8 @@ def _convert_path(self, path, transform, clip=False, simplify=None): | |||
return ps | |||
|
|||
def _get_clip_path(self, clippath, clippath_transform): | |||
id = self._clip_paths.get((clippath, clippath_transform)) | |||
key = (clippath, clippath_transform.get_matrix().tostring()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is clippath immutable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is clippath_transform always affine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like get_matrix
is defined on the Transform
class so I think it should always be there, but the hash will just ignore the non-affine part.
clippath might be mutable, but it does not define __eq__
(assuming it is some class defined in path.py) so we are still getting the old py2k memory-address-as-hash behavior here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose it's possible that clippath_transform is not always affine (though I don't know if that ever happens in practice). Maybe id(clippath_transform)
would work here? (It would at least give us the old Python 2.x behavior).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is no downside, ID is definitely the way to go IMHO...
@tacaswell, I haven't looked into this in detail, but after reading the comments on this and related issues, I conclude that if you change the line to key = (clippath, id(clippath_transform)) then everyone, and all Python versions, will be happy. |
@efiring I agree, I just have not gotten to it yet. |
Fixed and re-based. |
@tacaswell - this doesn't merge cleanly. Would you mind rebasing and I'll merge. |
Base key on the id of the transform. This maintains the old behavior and does not break the python hashable object model. changed the variable id -> pid so as to not shadow the method `id` Closes matplotlib#2828
@pelson Done |
BUG : don't use mutable objects as dictionary keys
_get_clip_path was returning '<built-in function id>' instead of the ps-function name like it should have been. This was introduced in 9b9c0c6 in PR matplotlib#2927. Closes matplotlib#3528
_get_clip_path was returning '<built-in function id>' instead of the ps-function name like it should have been. This was introduced in 9b9c0c6 in PR matplotlib#2927. Closes matplotlib#3523
Base key on the string version of the transform matrix
This addresses the core issue (we are trying to use a mutable object as a key) instead of breaking the data-model in one of two ways.
Closes #2828
Alternate to #2909