Skip to content

Incorrect check of runtime_checkable protocol which is not used @ class decorator #20787

@mixilchenko

Description

@mixilchenko

Bug Report

When Protocol is not marked with runtime_checkable decorator, isinstance(instance, runtime_checkable(ProtocolClass)) gives incorrect error.

This could be pretty useful when you don't want to mark protocol as runtime_checkable for the execution while in tests you would like to check protocol compliance

To Reproduce

playground link - https://mypy-play.net/?mypy=master&python=3.12&gist=54f484ed23e70f7d771f08bf839f8e4e

Expected Behavior

Success: no issues found in 1 source file

Actual Behavior

main.py:20: error: Only @runtime_checkable protocols can be used with instance and class checks  [misc]
Found 1 error in 1 file (checked 1 source file)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-runtime-semanticsmypy doesn't model runtime semantics correctly

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions