Skip to content

Fixed protocol check failing for inherited class/static methods#542

Merged
agronholm merged 2 commits intoagronholm:masterfrom
emmanuel-ferdman:master
Feb 6, 2026
Merged

Fixed protocol check failing for inherited class/static methods#542
agronholm merged 2 commits intoagronholm:masterfrom
emmanuel-ferdman:master

Conversation

@emmanuel-ferdman
Copy link
Copy Markdown
Contributor

Changes

Fixes #539.

When checking if a class implements a protocol with a classmethod or staticmethod, typeguard only looked at the class's own __dict__ and missed inherited methods. This caused subclasses to fail protocol checks even when they properly inherit the required classmethod from a parent. The fix traverses the MRO to find where the method is actually defined.

Checklist

If this is a user-facing code change, like a bugfix or a new feature, please ensure that
you've fulfilled the following conditions (where applicable):

  • You've added tests (in tests/) added which would fail without your patch
  • You've updated the documentation (in docs/, in case of behavior changes or new
    features)
  • You've added a new changelog entry (in docs/versionhistory.rst).

@coveralls
Copy link
Copy Markdown

coveralls commented Jan 15, 2026

Coverage Status

coverage: 94.734% (+0.01%) from 94.721%
when pulling b82a84d on emmanuel-ferdman:master
into 15c884b on agronholm:master.

@agronholm
Copy link
Copy Markdown
Owner

Yeah, I'll try to get around it today or tomorrow. Should go into the next release if it's OK.

Copy link
Copy Markdown
Owner

@agronholm agronholm left a comment

Choose a reason for hiding this comment

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

Seems simple enough. Thanks!

@agronholm agronholm merged commit be72808 into agronholm:master Feb 6, 2026
11 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.

False positive in @classmethod check for subclasses

3 participants