[issue34676] Guarantee that divmod() and PyNumber_Divmod() return a 2-tuple

2018-09-17 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- dependencies: +MagicMock.__divmod__ should return a pair ___ Python tracker ___ ___ Python-bugs-list

[issue34676] Guarantee that divmod() and PyNumber_Divmod() return a 2-tuple

2018-09-17 Thread Paul Ganssle
Paul Ganssle added the comment: @Serhiy I like the "convert to a tuple" idea before returning *better*, though I think I'd prefer to just check that it's tuple-like, something like: if not all(hasattr(return_val, attr) for attr in ['__getitem__', '__len__']) or len(return_val) != 2:

[issue34676] Guarantee that divmod() and PyNumber_Divmod() return a 2-tuple

2018-09-14 Thread Karthikeyan Singaravelan
Change by Karthikeyan Singaravelan : -- nosy: +xtreak ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https:/

[issue34676] Guarantee that divmod() and PyNumber_Divmod() return a 2-tuple

2018-09-14 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: An alternate idea: convert the result of __divmod__ and __rdivmod__ to tuple instead raising an error. This will support the case of returning a list. I didn't implement this initially because I think this case is very unlikely occurred in real code. Simi

[issue34676] Guarantee that divmod() and PyNumber_Divmod() return a 2-tuple

2018-09-14 Thread Zachary Ware
Zachary Ware added the comment: I share Paul's concern about somebody using this (mis-?)feature and being unnecessarily broken. However, such a restriction would have prevented the segfault that was reported and fixed in bpo-31577, and would save any other users of PyNumber_Divmod from havi