Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"argument is not compatible with the protocol" when inheriting from Protocol #457

Open
2 tasks done
bersbersbers opened this issue Apr 25, 2024 · 0 comments
Open
2 tasks done
Labels

Comments

@bersbersbers
Copy link

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.2.1

Python version

3.12.1

What happened?

Typeguard reports incompatibilities between a the values of a type variable and its type (I hope that makes sense). The value of type_argument is Class, which is a type derived from Base, so it should be compatible with type[Base].

How can we reproduce the bug?

bug.py

from typing import Protocol, runtime_checkable

from typeguard import typechecked

@runtime_checkable
class Base(Protocol):
    number: int

class Class(Base):
    number: int

@typechecked
def bug(type_argument: type[Base]) -> None:
    print(type_argument)

# mypy and pyright say this is OK:
type_argument: type[Base] = Class

# typeguard says this is not ok:
bug(Class)
mypy bug.py
pyright bug.py
python bug.py
typeguard.TypeCheckError: argument "type_argument" (class __main__.Class) is not compatible with the Base protocol
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant