New submission from Serhiy Storchaka <storchaka+cpyt...@gmail.com>:

It is documented that divmod() returns a pair of numbers, but the 
implementation doesn't enforce this. Actually divmod() just returns the result 
of __divmod__() or __rdivmod__() without checking it. PyNumber_Divmod() is 
documented as the C equivalent of divmod(). But since it returns a 2-tuple in 
all implemented cases, the user code can expect that it always return a 
2-tuple. This can lead to hidden bugs similar to issue31577.

I think there are no reasons of returning anything except a 2-tuple from 
divmod(). Forcing this conditions can save third-party code from crashes. The 
following PR make divmod() and PyNumber_Divmod() always returning a 2-tuple.

----------
components: Interpreter Core
messages: 325341
nosy: mark.dickinson, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Guarantie that divmod() and PyNumber_Divmod() return a 2-tuple
type: enhancement
versions: Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue34676>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to