This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients michael.foord, serhiy.storchaka
Date 2018-09-17.19:45:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1537213558.4.0.956365154283.issue34716@psf.upfronthosting.co.za>
In-reply-to
Content
It is documented, that divmod() returns a pair. It is usually used with tuple unpacking:

    x, y = divmod(a, b)

But this doesn't work when one of arguments is a MagicMock.

>>> from unittest.mock import *
>>> x, y = divmod(MagicMock(), 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: not enough values to unpack (expected 2, got 0)

I expect that tuple unpacking will work with the result of MagicMock.__divmod__(). There possible following options:

1. Return some constant value, e.g. (1, 0).

2. Return a pair of new MagicMock instances.

3. Define __divmod__ in terms of __floordiv__ and __mod__. This will automatically return a pair of MagicMock instances by default, but setting return values for __floordiv__ and __mod__ will affect the result of __divmod__.

What is more preferable?
History
Date User Action Args
2018-09-17 19:45:58serhiy.storchakasetrecipients: + serhiy.storchaka, michael.foord
2018-09-17 19:45:58serhiy.storchakasetmessageid: <1537213558.4.0.956365154283.issue34716@psf.upfronthosting.co.za>
2018-09-17 19:45:58serhiy.storchakalinkissue34716 messages
2018-09-17 19:45:58serhiy.storchakacreate