Things to check first
Typeguard version
4.4.4
Python version
3.13.9
What happened?
It seems that the protocol check for @classmethods when a base class implements the protocol, and a base class inherits it, the check fails.
The method is wrongly classified as an instance method.
How can we reproduce the bug?
This shows both a true negative (checking the base class), and a false positive (checking the subclass):
from typing import Protocol, Self
import typeguard
class HasClassFunc(Protocol):
@classmethod
def class_func(cls) -> Self: ...
class BaseClass:
@classmethod
def class_func(cls) -> Self:
return cls()
class SubClass(BaseClass):
pass
@typeguard.typechecked
def my_func(b: type[HasClassFunc]) -> HasClassFunc:
return b.class_func()
# succeeds
my_func(BaseClass)
# fails
my_func(SubClass)
Things to check first
I have searched the existing issues and didn't find my bug already reported there
I have checked that my bug is still present in the latest release
Typeguard version
4.4.4
Python version
3.13.9
What happened?
It seems that the protocol check for
@classmethods when a base class implements the protocol, and a base class inherits it, the check fails.The method is wrongly classified as an instance method.
How can we reproduce the bug?
This shows both a true negative (checking the base class), and a false positive (checking the subclass):