BUG : don't use mutable objects as dictionary keys#2927
BUG : don't use mutable objects as dictionary keys#2927pelson merged 1 commit intomatplotlib:masterfrom
Conversation
There was a problem hiding this comment.
yes, fixed, squashed and forced.
There was a problem hiding this comment.
Is clippath_transform always affine?
There was a problem hiding this comment.
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.
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.
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