Skip to content

gh-161591: sync inspect.signature() docs with actual function signature - #161594

Open
skirpichev wants to merge 3 commits into
python:mainfrom
skirpichev:inspect-sigs/161591
Open

skirpichev wants to merge 3 commits into
python:mainfrom
skirpichev:inspect-sigs/161591

Conversation

@skirpichev

@skirpichev skirpichev commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

@read-the-docs-community

read-the-docs-community Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35731918 | 📁 Comparing 06c7183 against main (f767423)

  🔍 Preview build  

2 files changed
± library/inspect.html
± whatsnew/changelog.html

@skirpichev

Copy link
Copy Markdown
Member Author

I prefer sphinx's version of the argument name. But renaming would introduce API break (though hardly it's severe), not sure if it worth.

Kept changes minimal, per issue description. But in fact many singnatures in the inspect module are out of sync with the real code and/or just invalid. Examples:

.. function:: getmembers(object[, predicate])
   [...]
.. function:: getmembers_static(object[, predicate])
   [...]

I would prefer to fix all in one shot, in this pr, if reviewers support this.

CC @sobolevn

Comment thread Doc/library/inspect.rst Resolved
@picnixz

picnixz commented Nov 8, 2026

Copy link
Copy Markdown
Member

I suggest you fix the docs properly even if naming is a bit.. wrong

@skirpichev

Copy link
Copy Markdown
Member Author

Ok, lets use obj...

But what about other signatures? Mentioned above could be fixed easily. Should I do it in this pr? Another one, formatargvalues() - probably must wait a better repr() for lambda, see #79037.

Comment thread Doc/library/inspect.rst Resolved

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mmh. Now that you say it, the docs are more meaningful. Here's what I suggest:

  • in this PR, align the docs with actual signature
  • in a follow-up, let's decide whether to break the signatures or not; I would be favorable to. We can have a deprecation period where first arguments become deprecated when passed as keyword arguments. I made a similar change for hashlib where parameter string/data were used across multiple hash functions and I deprecated the 'string' parameter.

An alternative is to mark the first parmaeter as positional-only in the docs. It's a lie but... it would also hide the fact that it's an implementation detail and will forbid users to use named params.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@skirpichev

Copy link
Copy Markdown
Member Author

in this PR, align the docs with actual signature

Ok, lets keep this as is.

in a follow-up, let's decide whether to break the signatures or not; I would be favorable to. We can have a deprecation period where first arguments become deprecated when passed as keyword arguments.

You meant:

  1. deprecate obj as positional or keyword
  2. make it positional-only, rename
  3. then allow it as keyword.

Sure, we can introduce breaking change that way, but IMO it's overkill. Hardly someone now uses signature(obj=foo) form versus positional argument.

An alternative is to mark the first parameter as positional-only in the docs.

Then next time someone else will point to inconsistency between docs and actual API.

@picnixz

picnixz commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Ok, so let's do the doc update first. That is, sync every signature with existing code first. And in a follow-up, I suggest we just break the signatures (but for that we need an issue and maybe someone else that would be ok with that)

@picnixz

picnixz commented Nov 8, 2026

Copy link
Copy Markdown
Member

Btw, which signature is typeshed using?

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

Labels

awaiting review docs Documentation in the Doc dir needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants