Skip to content

gh-72088: clarify inspect.ismethod returns False for class-level access#146505

Closed
Das-Chinmay wants to merge 1 commit into
python:mainfrom
Das-Chinmay:fix-inspect-ismethod-docs
Closed

gh-72088: clarify inspect.ismethod returns False for class-level access#146505
Das-Chinmay wants to merge 1 commit into
python:mainfrom
Das-Chinmay:fix-inspect-ismethod-docs

Conversation

@Das-Chinmay
Copy link
Copy Markdown
Contributor

@Das-Chinmay Das-Chinmay commented Mar 27, 2026

inspect.ismethod() returns False when a method is accessed through the
class rather than an instance (because the result is a plain function, not a
bound method). This trips up users coming from Python 2, where unbound methods
existed. The current one-liner docstring gives no hint of this behaviour.

Adds a short note and a cross-reference to the instance-methods section of
the language reference so readers can understand why.

Fixes issue gh-72088

  • Base: python/cpython:main
  • Head: Das-Chinmay:fix-inspect-ismethod-docs

📚 Documentation preview 📚: https://cpython-previews--146505.org.readthedocs.build/

…l access

Accessing a method through the class returns a plain function, not a
bound method, so ismethod() returns False in that case.  Add a note
and a cross-reference to the 'instance methods' section of the data
model reference to explain this.
Copy link
Copy Markdown
Member

@johnslavik johnslavik left a comment

Choose a reason for hiding this comment

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

Consider using a more modern .. note:: admonition.

cc @encukou

@encukou
Copy link
Copy Markdown
Member

encukou commented Apr 15, 2026

Note: is fine, I don't think this needs a box.

Should we also note in the inspect.isfunction docs that it returns False for bound methods?
And in is{coroutine,generator,asyncgen}function functions that those return True for bound methods made from "their" functions?

@github-actions
Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@encukou
Copy link
Copy Markdown
Member

encukou commented May 18, 2026

Finished and merged in #150013.

@encukou encukou closed this May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review docs Documentation in the Doc dir skip news stale Stale PR or inactive for long period of time.

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants