See
from inspect import signature
import math
import traceback
import sys
print(sys.version)
funcs_to_try = [
math.acos, math.acosh, math.asinh, math.atan, math.atan2, math.cos, math.cosh,
math.degrees, math.erf, math.erfc, math.exp, math.log, math.log10, math.radians,
math.sin, math.sinh, math.sqrt, math.tan, math.tanh
]
for func in funcs_to_try:
try:
print(f"{func.__name__}: {signature(func)}")
except ValueError:
print(f"{func.__name__}: Didn't work.")
traceback.print_exc(file=sys.stdout)
# 3.12.4 (tags/v3.12.4:8e8a4ba, Jun 6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)]
# acos: (x, /)
# acosh: (x, /)
# asinh: (x, /)
# atan: (x, /)
# atan2: (y, x, /)
# cos: (x, /)
# cosh: (x, /)
# degrees: (x, /)
# erf: (x, /)
# erfc: (x, /)
# exp: (x, /)
# log: Didn't work.
# Traceback (most recent call last):
# File "...\AppData\Roaming\JetBrains\PyCharm2024.1\scratches\scratch.py", line 16, in <module>
# print(f"{func.__name__}: {signature(func)}")
# ^^^^^^^^^^^^^^^
# File "...\AppData\Local\Programs\Python\Python312\Lib\inspect.py", line 3335, in signature
# return Signature.from_callable(obj, follow_wrapped=follow_wrapped,
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# File "...\AppData\Local\Programs\Python\Python312\Lib\inspect.py", line 3075, in from_callable
# return _signature_from_callable(obj, sigcls=cls,
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# File "...\AppData\Local\Programs\Python\Python312\Lib\inspect.py", line 2592, in _signature_from_callable
# return _signature_from_builtin(sigcls, obj,
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# File "...\AppData\Local\Programs\Python\Python312\Lib\inspect.py", line 2382, in _signature_from_builtin
# raise ValueError("no signature found for builtin {!r}".format(func))
# ValueError: no signature found for builtin <built-in function log>
# log10: (x, /)
# radians: (x, /)
# sin: (x, /)
# sinh: (x, /)
# sqrt: (x, /)
# tan: (x, /)
# tanh: (x, /)
Why is math.log
the only function out of this long list on which inspect.signature
fails? I’m curious if there’s something I can do to get this working.
I understand there’s some historical trickiness with inspect.signature
and built-in functions, but it works for all these other functions so it seems like it should work for math.log
.