Skip to content

Recommend is in the comparison-with-callable documentation - #11754

Open
thisisshivamtiwari wants to merge 1 commit into
pylint-dev:mainfrom
thisisshivamtiwari:doc-7724-comparison-with-callable-is
Open

thisisshivamtiwari wants to merge 1 commit into
pylint-dev:mainfrom
thisisshivamtiwari:doc-7724-comparison-with-callable-is

Conversation

@thisisshivamtiwari

Copy link
Copy Markdown

Type of Changes

Type
✓ 📜 Docs

Description

As suggested in #7724 (comment), this adds an "Additional details" section to the comparison-with-callable message page. It covers code that compares callables on purpose, such as checking which function was passed in:

  • Use is instead of ==. Plain functions are only equal to themselves, so the result is the same. is is not in the operators this check looks at, so the message is not emitted.
  • Bound methods are the exception. obj.method is obj.method is False, because each attribute access creates a new bound method, so the section suggests comparing __func__ instead.

I checked both claims locally. callback is print is not reported and callback == print is. For a bound method cb = obj.greet, cb is obj.greet is False and cb.__func__ is Greeter.greet is True. The new details.rst passes the rstcheck, prettier and codespell pre-commit hooks, and docutils renders it without warnings. doc/test_messages_documentation.py -k comparison-with-callable passes. I did not build the full Sphinx docs locally.

This is a documentation-only change, so I did not add a news fragment.

Closes #7724

🤖 Generated with Claude Code

Code that compares callables on purpose, for example to check which
function was passed in, can use `is`: plain functions are only equal to
themselves, and the message is not emitted for identity comparisons.
Document this, along with the bound method caveat.

Closes pylint-dev#7724

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Doc why is is superior to == in comparison-with-callable when comparing two callables

2 participants