This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: cmath.log has an invalid signature
Type: behavior Stage:
Components: Extension Modules Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: corona10, mark.dickinson, vstinner
Priority: normal Keywords:

Created on 2021-09-16 09:09 by mark.dickinson, last changed 2022-04-11 14:59 by admin.

Messages (5)
msg401933 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2021-09-16 09:09
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
msg401937 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2021-09-16 11:45
Issue #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)
msg401938 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2021-09-16 12:12
See also #36306 and #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 `None` doesn't seem like a terrible option.

(BTW, just to forestall the suggestion, a default of `math.e` or `cmath.e` is definitely *not* the right thing to use as a default: `math.e` is not exactly Euler's value for e, and `log` base `math.e` is likely to be less accurate than plain natural log.)
msg401939 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2021-09-16 12:35
> and `log` base `math.e` is likely to be less accurate than plain natural log

Nope, 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.
msg401940 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-09-16 12:50
The current Argument Clinic syntax for math.log() is:

--------------
/*[clinic input]
math.log

    x:    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.
History
Date User Action Args
2022-04-11 14:59:50adminsetgithub: 89381
2021-09-24 15:55:05corona10setnosy: + corona10
2021-09-16 12:50:51vstinnersetnosy: + vstinner
messages: + msg401940
2021-09-16 12:35:38mark.dickinsonsetmessages: + msg401939
2021-09-16 12:12:30mark.dickinsonsetmessages: + msg401938
2021-09-16 11:45:41mark.dickinsonsetmessages: + msg401937
2021-09-16 09:09:13mark.dickinsonsettype: behavior
2021-09-16 09:09:00mark.dickinsoncreate