Skip to content

Mark math.log parameters as positional-only#16042

Merged
AlexWaygood merged 1 commit into
python:mainfrom
Osamaali313:fix/math-log-positional-only
Jul 19, 2026
Merged

Mark math.log parameters as positional-only#16042
AlexWaygood merged 1 commit into
python:mainfrom
Osamaali313:fix/math-log-positional-only

Conversation

@Osamaali313

Copy link
Copy Markdown
Contributor

math.log is a C function that takes no keyword arguments. At runtime both keyword forms fail:

>>> import math
>>> math.log(x=8)
TypeError: math.log() takes no keyword arguments
>>> math.log(8, base=2)
TypeError: math.log() takes no keyword arguments

But the stub omits the trailing /, so type checkers currently accept math.log(x=8) / math.log(8, base=2) — code that type-checks clean yet crashes at runtime.

Every sibling in the same module is already positional-only — isqrt, ldexp, lgamma, log10, log1p, log2, modf all end with , / — and cmath.log is def log(z: _C, base: _C = ..., /) -> complex: .... math.log is the only one missing it.

Add , / (a positional-only parameter may still carry a default):

def log(x: _SupportsFloatOrIndex, base: _SupportsFloatOrIndex = ..., /) -> float: ...

`math.log` is a C function that accepts no keyword arguments; at runtime
`math.log(x=8)` and `math.log(8, base=2)` both raise
`TypeError: math.log() takes no keyword arguments`. The stub omits the
trailing `/`, so type checkers wrongly accept those keyword forms.

Every sibling in the same module is already positional-only — isqrt, ldexp,
lgamma, log10, log1p, log2, modf all end with `, /` — and `cmath.log` is also
`(z, base=..., /)`. `math.log` is the lone exception. Add `, /` (a
positional-only parameter may still carry a default).
Copilot AI review requested due to automatic review settings July 19, 2026 21:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@AlexWaygood

Copy link
Copy Markdown
Member

thanks!

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@AlexWaygood
AlexWaygood merged commit e4e0f7e into python:main Jul 19, 2026
73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants