I recently merged a PR authored by Sergey Kirpichev that fixes inspect.signature (which previously failed with a ValueError) for math.log and cmath.log. A side-effect of that change is that math.log and cmath.log now accept the Python value None for the base argument. That is:
>>> from math import log
>>> log(2.3, None)
0.8329091229351039
Previously, this was a TypeError.
In comments on the original issue, Raymond Hettinger alludes to the new API as being “damaged”:
there seems to be willingness to damage the function rather than on improving the capabilities of signature objects […]
and
people should be working on that problem rather than damaging the underlying functions […]
I’m not seeing the damage here, and accepting None seems to me like a reasonable trade-off for the benefit of having usable signatures. The None default is a common idiom, and at least one other function in the math module already accepts None in this way (as do many non-math functions, of course):
>>> from math import perm
>>> perm(10, None)
3628800
More generally, I’d expect that having functions with signatures expressible in standard form would aid consistency and compatibility with other Python implementations, as well as helping tools that need to do inspection of signatures for one reason or another.
Is there a general principle that we should avoid these sorts of changes? What are the downsides of allowing None in this kind of situation?
