{"action":"opened","issue":{"url":"https://api.github.com/repos/biopython/biopython/issues/929","repository_url":"https://api.github.com/repos/biopython/biopython","labels_url":"https://api.github.com/repos/biopython/biopython/issues/929/labels{/name}","comments_url":"https://api.github.com/repos/biopython/biopython/issues/929/comments","events_url":"https://api.github.com/repos/biopython/biopython/issues/929/events","html_url":"https://github.com/biopython/biopython/issues/929","id":176169400,"number":929,"title":"Deprecate SeqRecord hash comparison (eg in dicts and sets)","user":{"login":"peterjc","id":63959,"avatar_url":"https://avatars.githubusercontent.com/u/63959?v=3","gravatar_id":"","url":"https://api.github.com/users/peterjc","html_url":"https://github.com/peterjc","followers_url":"https://api.github.com/users/peterjc/followers","following_url":"https://api.github.com/users/peterjc/following{/other_user}","gists_url":"https://api.github.com/users/peterjc/gists{/gist_id}","starred_url":"https://api.github.com/users/peterjc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterjc/subscriptions","organizations_url":"https://api.github.com/users/peterjc/orgs","repos_url":"https://api.github.com/users/peterjc/repos","events_url":"https://api.github.com/users/peterjc/events{/privacy}","received_events_url":"https://api.github.com/users/peterjc/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-10T08:54:35Z","updated_at":"2016-09-10T08:54:35Z","closed_at":null,"body":"As discussed in #873 with @kblin, we should also do something to the ``SeqRecord`` default ``__hash__`` method which currently means you can do ``my_record in set_of_records`` but not ``my_record in list_of_records``\r\n\r\ne.g.\r\n\r\n```\r\n>>> from Bio import SeqIO\r\n>>> list_of_records = list(SeqIO.parse(\"cor6_6.gb\", \"gb\"))\r\n>>> set_of_records = set(list_of_records)\r\n>>> my_record = list_of_records[3]\r\n```\r\n\r\nThis used to work, but as of Biopython 1.67 triggers the new exception:\r\n\r\n```\r\n>>> my_record in list_of_records\r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 1, in <module>\r\n  File \"/Library/Python/2.7/site-packages/Bio/SeqRecord.py\", line 727, in __eq__\r\n    raise NotImplementedError(_NO_SEQRECORD_COMPARISON)\r\nNotImplementedError: SeqRecord comparison is deliberately not implemented. Explicitly compare the attributes of interest.\r\n```\r\n\r\nThis currently works because internally like a dict it uses ``hash(my_record)``:\r\n\r\n```\r\n>>> my_record in set_of_records\r\nTrue\r\n```\r\n\r\nShould we make our ``SeqRecord`` unhashable, i.e. match:\r\n\r\n```\r\n>>> hash([])\r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 1, in <module>\r\nTypeError: unhashable type: 'list'\r\n```\r\n\r\nwith:\r\n\r\n```\r\n>>> hash(my_record)\r\nTraceback (most recent call last):\r\n  ...\r\nTypeError: unhashable type: 'SeqRecord'\r\n```\r\n\r\nThis would mean we'd get this:\r\n\r\n```\r\n>>> my_record in set_of_records\r\nTraceback (most recent call last):\r\n  ...\r\nTypeError: unhashable type: 'SeqRecord'\r\n```\r\n\r\nIt would be more consistent, but again could break some existing code which is deliberately using the object-comparison via the implicit hashing.\r\n\r\nThis change should be gradual with a couple of releases where using the ``SeqRecord`` object's ``__hash__`` method triggers a warning."}}
{"actor":{"display_login":"peterjc"}}