Skip to content

Fix __doc__ on unbound method#2958

Merged
DanielNoord merged 2 commits intopylint-dev:mainfrom
DanielNoord:fix-unbound
Feb 15, 2026
Merged

Fix __doc__ on unbound method#2958
DanielNoord merged 2 commits intopylint-dev:mainfrom
DanielNoord:fix-unbound

Conversation

@DanielNoord
Copy link
Collaborator

@DanielNoord DanielNoord commented Feb 9, 2026

Type of Changes

Type
🐛 Bug fix

Description

Fixes the issue as described in #2847

The reproducer for the crash is:

class Executor:
    def submit(self): ...


class ThreadPoolExecutor(Executor):
    def submit(self): ...

    submit.__doc__ = Executor.submit.__doc__

That could be fixed in pylint (by not calling pytype() on NodeNG subclasses that don't have it), but that seems unnecessary.

Instead we can (I hope/think) better represent the actual object model by letting UnboundMethodModel inherit from FunctionModel. That feels like it would make sense? The test doesn't pass without this fix.

We could add attr___doc__ on UnboundMethodModel but for me this feels like it better fits at least my own mental model of Python objects 😅

@codecov
Copy link

codecov bot commented Feb 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.30%. Comparing base (c75c0a0) to head (08fa1a3).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2958      +/-   ##
==========================================
- Coverage   93.31%   93.30%   -0.01%     
==========================================
  Files          92       92              
  Lines       11292    11295       +3     
==========================================
+ Hits        10537    10539       +2     
- Misses        755      756       +1     
Flag Coverage Δ
linux 93.16% <100.00%> (-0.01%) ⬇️
pypy 93.30% <100.00%> (-0.01%) ⬇️
windows 93.28% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
astroid/interpreter/objectmodel.py 95.95% <100.00%> (-0.39%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@emmanuel-ferdman
Copy link
Contributor

Hey @DanielNoord! I was just working on this same issue. I should've commented that but no worries 😄 .
I agree that UnboundMethodModel should extend FunctionModel. I would like to suggest this pr to also include fixes to two releated prolems that I think are still happening:

  • ObjectModel-only dunders like __eq__, __hash__, __repr__ still return Unknown instead of Uninferable because FunctionModel inherits from ObjectModel and doesn't override those.
class A:
    def test(self): pass

A.test.__eq__  # Returns Unknown, not Uninferable
  • super().__doc__ has the same problem.
class Base:
    def method(self):
        return super().__doc__

Base().method()  # Returns Unknown, not Uninferable

I think the fix can be adding Unknown filtering to UnboundMethod.getattr/igetattr and Super.igetattr (same pattern PR #2847 used for BaseInstance and ClassDef) so Unknown placeholders fall through to the proxied object. I have this implementation in a commit on my fork branch - feel free to take the changes if they're relevant to your PR, or let me know if I should open a separate PR to address the additional cases.

@DanielNoord
Copy link
Collaborator Author

@emmanuel-ferdman Let's open a different PR for your fix! It is indeed valuable, but I think we can apply both as they have somewhat different (but good) effects 😄

Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

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

Looks good!

@DanielNoord
Copy link
Collaborator Author

@jacobtylerwalls Unrelated to this PR, but this action failed: https://github.com/pylint-dev/astroid/actions/runs/22041554054

@DanielNoord DanielNoord merged commit 177cf4d into pylint-dev:main Feb 15, 2026
19 checks passed
pylint-backport bot pushed a commit that referenced this pull request Feb 15, 2026
(cherry picked from commit 177cf4d)
DanielNoord added a commit that referenced this pull request Feb 15, 2026
(cherry picked from commit 177cf4d)
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.

3 participants