Repository navigation
cmath.log has an invalid signature (ditto math.log) #89381
Description
Activity
inspect.signature reports that the cmath.log function has an invalid signature:
Python 3.11.0a0 (heads/fix-44954:d0ea569eb5, Aug 19 2021, 14:59:04) [Clang 12.0.0 (clang-1200.0.32.29)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import cmath >>> import inspect >>> inspect.signature(cmath.log) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/mdickinson/Python/cpython/Lib/inspect.py", line 3215, in signature return Signature.from_callable(obj, follow_wrapped=follow_wrapped, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/mdickinson/Python/cpython/Lib/inspect.py", line 2963, in from_callable return _signature_from_callable(obj, sigcls=cls, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/mdickinson/Python/cpython/Lib/inspect.py", line 2432, in _signature_from_callable return _signature_from_builtin(sigcls, obj, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/mdickinson/Python/cpython/Lib/inspect.py", line 2244, in _signature_from_builtin return _signature_fromstr(cls, func, s, skip_bound_arg) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/mdickinson/Python/cpython/Lib/inspect.py", line 2114, in _signature_fromstr raise ValueError("{!r} builtin has invalid signature".format(obj)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: <built-in function log> builtin has invalid signature
- added3.9 (EOL)end of lifeend of life3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Sep 16, 2021 Issue bpo-43067 is similar. I'm not sure what the best solution is in this case:
- un-argument-clinic cmath.log, and document the signature using two lines (similar to range):
log(z) log(z, base)
- change the behaviour of cmath.log so that the second argument is allowed be None (and defaults to None)
See also bpo-36306 and bpo-29299. There may be nothing to be done here, but it would be nice if math.log and cmath.log at least behaved in the same way. A default of
Nonedoesn't seem like a terrible option.(BTW, just to forestall the suggestion, a default of
math.eorcmath.eis definitely not the right thing to use as a default:math.eis not exactly Euler's value for e, andlogbasemath.eis likely to be less accurate than plain natural log.)and
logbasemath.eis likely to be less accurate than plain natural logNope, that's nonsense, since the two-argument form simply divides by log(base), and while log(math.e) is mathematically not exactly 1 (its exact value, assuming IEEE 754 binary64, starts 0.9999999999999999468176229339410862948..., which is off from 1.0 by around 0.48 ulps), it's *just* close enough that with a well-behaved libm log implementation it's exactly 1.0 after rounding.
I still don't like the idea of math.e as a default value here, but I'd have to work harder to identify why it makes me uneasy.
The current Argument Clinic syntax for math.log() is:
--------------
/*[clinic input]
math.logx: object [ base: object(c_default="NULL") = math.e ] /Return the logarithm of x to the given base.
(...)
--------------math.log.__text_signature__ is None. __text_signature__ is used by inspect.signature().
I guess that it's a bug in Argument Clinic.
29 remaining items
discuss.org
discuss.python.org?
@arhadthedev
discuss.python.orgindeed! Thank you.Discussion opened at https://discuss.python.org/t/should-none-defaults-for-optional-arguments-be-discouraged/23554
Reacted by Erlend E. AaslandReacted by Gregory P. SmithClosing as "won't fix".
- changed the title
[-]cmath.log has an invalid signature[/-][+]cmath.log has an invalid signature (ditto math.log)[/+]on May 14, 2026 Lets reopen this.
This issue still valid. We have much generic one, #73536, but no progress for years. Though, this case seems to be more specific and simple.
I suggest solution along sketch, presented above, i.e. using symbolic constant for the default. (I.e.
cmath.erather than2.718281828459045.)Other builtins and/or parts of the stdlib also could benefit from this change. For example, this is how
list.index()signature now looks like:>>> inspect.signature(list.index) <Signature (self, value, start=0, stop=9223372036854775807, /)>Wouldn't this be clearer
>>> inspect.signature(list.index) <Signature (self, value, start=0, stop=sys.maxsize, /)>?
Respectively, proposed signature will look like:
>>> inspect.signature(cmath.log) <Signature (z, base=cmath.e, /)>or
>>> inspect.signature(cmath.log) <Signature (z, base=e, /)>PS: For completeness, now we have the PEP 661. Sentinel could be used as an alternative to None. See
functools.reduce().@skirpichev Please could you unassign me from this issue? (I don't have the permissions to do that myself.)
- removed3.11only security fixesonly security fixes3.10 (EOL)end of lifeend of life3.12only security fixesonly security fixes
on Aug 19, 2026
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs