Skip to content

gh-89381: Fix signature for math.log and cmath.log - #101115

Closed
hauntsaninja wants to merge 2 commits into
python:mainfrom
hauntsaninja:gh-89381
Closed

hauntsaninja wants to merge 2 commits into
python:mainfrom
hauntsaninja:gh-89381

Conversation

@hauntsaninja

@hauntsaninja hauntsaninja commented Jan 18, 2023 •

Copy link
Copy Markdown
Contributor

The optional group in math.log seems unnecessary, as far as I can tell. Once we remove this, Argument Clinic knows what to do.

For cmath, we just do what math is already doing: use c_default = NULL (so the actual runtime logic is unchanged), but mark cmath.e as the fake default value.

The optional group in math.log seems unnecessary, as far as I can tell.
Once we remove this, Argument Clinic knows what to do.

For cmath, we just do what math is doing, which is use c_default = NULL
(so the actual runtime logic is unchanged), but mark cmath.e as the fake
default value.
@skirpichev

Copy link
Copy Markdown
Member

Seems to be working. I'll keep #101070 in case someone will prefer base=None defaults. Now we got
something like this:

>>> inspect.signature(math.log)
<Signature (x, base=2.718281828459045, /)>

Maybe this is slightly cryptic: 1) magic constant appear, 2) there is an illusion that the special base=math.e works internally as log(x)/log(base). BTW, shouldn't be there regression tests (e.g. for the original issue with inspect.signature(cmath.log))?

Also, I think that docs for the math.log/cmath.log should be adapted. To me it was a surprise, that this requires a manual adjustment after fixing the docstring.

@mdickinson
mdickinson self-requested a review January 19, 2023 16:28
@mdickinson

Copy link
Copy Markdown
Member

Maybe this is slightly cryptic: 1) magic constant appear, 2) there is an illusion that the special base=math.e works internally as log(x)/log(base).

Agreed on both points; I prefer the solution in #101070.

@skirpichev

Copy link
Copy Markdown
Member

@mdickinson, I can restore #101070, if you wish. But after #101123 I'm not sure that a broken signature is an issue for CPython.

@mdickinson

Copy link
Copy Markdown
Member

@skirpichev The changes in #101070 look good to me, modulo one documentation suggestion (left in a comment). If you resurrect it, I'd be happy to merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

4 participants