[New-bugs-announce] [issue21193] pow(a, b, c) should not raise TypeError when b is negative and c is provided

Josh Rosenberg report at bugs.python.org
Thu Apr 10 02:24:57 CEST 2014


New submission from Josh Rosenberg:

While checking the exceptions used to compare existing behavior while investigating #20539, I noticed a weird behavior in pow() (implemented by long_pow in longobject.c). If a 3rd argument (the modulus) is provided, and the 2nd argument (the exponent) is negative, the function raises TypeError. To my knowledge, TypeError should never be used for this purpose; some functions raise OverflowError for negative values (which violates the documented purpose of OverflowError, but the documents don't match CPython's implementation), others use ValueError (which I believe is appropriate, since it's not a matter of a C type limitation, the function is just logically restricted to the range [0,Largest possible PyLong]. 

I recommend switching to ValueError, possibly with a deprecation notice before making the switch if people think someone might rely on this behavior.

Related: #457066

----------
components: Interpreter Core
messages: 215860
nosy: josh.rosenberg
priority: normal
severity: normal
status: open
title: pow(a, b, c) should not raise TypeError when b is negative and c is provided
type: behavior
versions: Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21193>
_______________________________________


More information about the New-bugs-announce mailing list