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 <rep...@bugs.python.org>
<http://bugs.python.org/issue21193>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to