agronholm / typeguard

Run-time type checker for Python
Other
1.56k stars 114 forks source link

Class is not compatible with protocol because some method should be an instance method but it's a static method #498

Closed bersbersbers closed 3 weeks ago

bersbersbers commented 1 month ago

Things to check first

Typeguard version

4.4.0

Python version

3.13.0

What happened?

Typeguard says that

typeguard.TypeCheckError: argument "arg" (class code.Class) is not compatible with the Proto protocol because its 'method' method should be an instance method but it's a static method

I think it is wrong saying that.

How can we reproduce the bug?

bug.py

from typeguard import install_import_hook

install_import_hook()

from code import Class, function

function(Class)

code.py

from typing import Protocol

class Proto(Protocol):
    def method(self): ...

class Class(Proto):
    def method(self): ...

def function(arg: type[Proto]): ...

Then run python bug.py.

agronholm commented 1 month ago

Ah...checking against a protocol as a class – I think my test suite missed that.