Skip to content

typing.Protocol is explicitly treated as not a type #21940

Description

@chet-manley

Bug Report

At runtime, isinstance(typing.Protocol, type) is True. When type checking, mypy appears to special-case Protocol:

  • mypy: <typing special form>
  • Pylance/Pyright: (class) Protocol

To Reproduce

from typing import Protocol

class A(Protocol): pass
    
assert Protocol in A.__bases__
bases: tuple[type, ...] = (Protocol, *A.__bases__)

playground (gist)

Expected Behavior

Same as Pyright, Protocol is a class (type), no errors.

Actual Behavior

main.py:5: error: Non-overlapping container check (element type: "<typing special form>", container item type: "type")  [comparison-overlap]
main.py:6: error: Argument 1 to <tuple> has incompatible type "<typing special form>"; expected "type"  [arg-type]

Your Environment

  • Mypy version used: 1.0.0, 1.10.1, 1.20.2, 2.3.1
  • Mypy command-line flags: --strict
  • Python version used: 3.6 - 3.14

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions