{"action":"created","issue":{"url":"https://api.github.com/repos/robofab-developers/fontParts/issues/264","repository_url":"https://api.github.com/repos/robofab-developers/fontParts","labels_url":"https://api.github.com/repos/robofab-developers/fontParts/issues/264/labels{/name}","comments_url":"https://api.github.com/repos/robofab-developers/fontParts/issues/264/comments","events_url":"https://api.github.com/repos/robofab-developers/fontParts/issues/264/events","html_url":"https://github.com/robofab-developers/fontParts/issues/264","id":314210236,"number":264,"title":"Check __hash__","user":{"login":"benkiel","id":878741,"avatar_url":"https://avatars3.githubusercontent.com/u/878741?v=4","gravatar_id":"","url":"https://api.github.com/users/benkiel","html_url":"https://github.com/benkiel","followers_url":"https://api.github.com/users/benkiel/followers","following_url":"https://api.github.com/users/benkiel/following{/other_user}","gists_url":"https://api.github.com/users/benkiel/gists{/gist_id}","starred_url":"https://api.github.com/users/benkiel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benkiel/subscriptions","organizations_url":"https://api.github.com/users/benkiel/orgs","repos_url":"https://api.github.com/users/benkiel/repos","events_url":"https://api.github.com/users/benkiel/events{/privacy}","received_events_url":"https://api.github.com/users/benkiel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-04-13T18:38:44Z","updated_at":"2018-04-13T20:56:38Z","closed_at":null,"author_association":"OWNER","body":"From @justvanrossum:\r\n\r\nIndeed, the fact these objects weren't hashable before implies they have an __eq__ method, which makes adding __hash__ tricky or even questionable. For each object with __hash__, please review the associated __eq__."},"comment":{"url":"https://api.github.com/repos/robofab-developers/fontParts/issues/comments/381258538","html_url":"https://github.com/robofab-developers/fontParts/issues/264#issuecomment-381258538","issue_url":"https://api.github.com/repos/robofab-developers/fontParts/issues/264","id":381258538,"user":{"login":"typesupply","id":4992934,"avatar_url":"https://avatars0.githubusercontent.com/u/4992934?v=4","gravatar_id":"","url":"https://api.github.com/users/typesupply","html_url":"https://github.com/typesupply","followers_url":"https://api.github.com/users/typesupply/followers","following_url":"https://api.github.com/users/typesupply/following{/other_user}","gists_url":"https://api.github.com/users/typesupply/gists{/gist_id}","starred_url":"https://api.github.com/users/typesupply/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/typesupply/subscriptions","organizations_url":"https://api.github.com/users/typesupply/orgs","repos_url":"https://api.github.com/users/typesupply/repos","events_url":"https://api.github.com/users/typesupply/events{/privacy}","received_events_url":"https://api.github.com/users/typesupply/received_events","type":"User","site_admin":false},"created_at":"2018-04-13T20:56:38Z","updated_at":"2018-04-13T20:56:38Z","author_association":"OWNER","body":"I made a small test to see figure this out:\r\n\r\n```python\r\nclass WrappedObject(object): pass\r\n\r\nclass WrapperObject(object):\r\n\r\n\tdef __init__(self, obj):\r\n\t\tself._wrapped = obj\r\n\r\n\tdef __eq__(self, other):\r\n\t\tif isinstance(other, self.__class__):\r\n\t\t\treturn self._wrapped == other._wrapped\r\n\t\traise NotImplementedError\r\n\r\n\r\nwrapped = WrappedObject()\r\nwrapper1 = WrapperObject(wrapped)\r\nwrapper2 = WrapperObject(wrapped)\r\n\r\nprint(wrapper1 == wrapper2)\r\n\r\nstorage = {}\r\nstorage[wrapper1] = 1\r\nstorage[wrapper2] = 2\r\nprint(storage)\r\n```\r\n\r\nThis works as expected. The `==` returns True. The wrappers can be used as keys in dicts.\r\n\r\nIf I try this:\r\n\r\n```python\r\nfrom defcon import Font\r\nfrom fontParts.world import RFont\r\n\r\nwrapped = Font()\r\nwrapper1 = RFont(wrapped)\r\nwrapper2 = RFont(wrapped)\r\n\r\nprint(wrapper1 == wrapper2)\r\n\r\nstorage = {}\r\nstorage[wrapper1] = 1\r\nstorage[wrapper2] = 2\r\nprint(storage)\r\n```\r\n\r\nThe `==` works as expected. When using the wrappers as keys, only one will be used as a key. This is happening because `__hash__` compare the `id` of the wrapped object and it's the same object so there can only be one key. That's neither right nor wrong as the expected behavior of that is in the eye of the beholder.\r\n\r\nIf I remove `__hash__` from `BaseObject` and `BaseFont` everything works. So, now I'm trying to remember why we needed a custom `__hash__`. I thought it was because of the key issue, but that doesn't appear to be a problem. Do you remember, @benkiel?"}}
{"actor":{"display_login":"typesupply"}}