Issue 28260: mock._Any and mock._Call implement eq but not hash (original) (raw)

Created on 2016-09-23 17:59 by Roy Williams, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (6)
msg277290 - (view) Author: Roy Williams (Roy Williams) * Date: 2016-09-23 17:59
I am investigating a migration to Python 3, and to facilitate this we are using the -3 flag as decribed here: https://docs.python.org/3/howto/pyporting.html#prevent-compatibility-regressions . When using this flag I encountered some issues inside of mock itself. Python 3 now requires you to implement __hash__ if you implement __eq__. See https://docs.python.org/3.6/reference/datamodel.html#object.%5F%5Fhash%5F%5F . {mock.ANY} # Fine in Python 2, Throws in Python 3 I've created a PR that explicitly sets the __hash__ method on these objects as None to ensure the behavior is consistent in Python 3 as well as Python 2. The folks over at testing-in-python suggested I submit a bug here first and then the fix can be backported to testing-cabal/mock https://github.com/testing-cabal/mock/pull/378
msg277365 - (view) Author: Antti Haapala (ztane) * Date: 2016-09-25 11:24
So you mean that unittest.mock should explicitly set `__hash__ = None`; but this is already what the unittest.mock does, in Python 3; there is no need to set `__hash__ = None`; it is the backport that needs to do this in order to stay compatible. There is no mock.py in 2.7.
msg277382 - (view) Author: Roy Williams (Roy Williams) * Date: 2016-09-25 16:06
Hey Antti My understanding is the version available on PyPi is now a strict backport of what's in Python 3, so they suggested filling the bug in bugs.python.org so it can be backported. http://lists.idyll.org/pipermail/testing-in-python/2016-September/006864.html Thanks, Roy On Sep 25, 2016 4:24 AM, "Antti Haapala" <report@bugs.python.org> wrote: > > Antti Haapala added the comment: > > So you mean that unittest.mock should explicitly set `__hash__ = None`; > but this is already what the unittest.mock does, in Python 3; there is no > need to set `__hash__ = None`; it is the backport that needs to do this in > order to stay compatible. There is no mock.py in 2.7. > > ---------- > nosy: +ztane > > _______________________________________ > Python tracker <report@bugs.python.org> > <http://bugs.python.org/issue28260> > _______________________________________ >
msg277387 - (view) Author: Antti Haapala (ztane) * Date: 2016-09-25 18:01
Well, as far as I understand, this is a bug in the backport only. The Python 2.6+ backport does not behave identically to Python 3 code in Python 2, unless `__hash__ = None` is added. unittest.mock in Python 3 is not affected in any way.
msg277388 - (view) Author: Ned Batchelder (nedbat) * (Python triager) Date: 2016-09-25 18:16
Roy, the code on GitHub isn't a literal copy of the Python 3 code, since it uses six, "from __future__ import", conditional imports of builtins, and so on. This can be fixed in GitHub.
msg277395 - (view) Author: Roy Williams (Roy Williams) * Date: 2016-09-25 18:41
OK, let's close this issue and I'll ping the TIP thread/this issue again. On Sun, Sep 25, 2016, 11:16 AM Ned Batchelder <report@bugs.python.org> wrote: > > Ned Batchelder added the comment: > > Roy, the code on GitHub isn't a literal copy of the Python 3 code, since > it uses six, "from __future__ import", conditional imports of builtins, and > so on. > > This can be fixed in GitHub. > > ---------- > > _______________________________________ > Python tracker <report@bugs.python.org> > <http://bugs.python.org/issue28260> > _______________________________________ >
History
Date User Action Args
2022-04-11 14:58:37 admin set github: 72447
2016-09-25 23:04:28 berker.peksag set status: open -> closedresolution: not a bugstage: resolved
2016-09-25 18:41:14 Roy Williams set messages: +
2016-09-25 18:16:35 nedbat set messages: +
2016-09-25 18:01:30 ztane set messages: +
2016-09-25 16:06:40 Roy Williams set messages: +
2016-09-25 11:24:40 ztane set nosy: + ztanemessages: +
2016-09-24 11:16:53 nedbat set nosy: + nedbat
2016-09-23 20:02:42 Roy Williams set type: behavior
2016-09-23 17:59:53 Roy Williams create