python / python/mypy

`typing.Protocol` is explicitly treated as not a `type`

Open
#21,940 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-protocols topic-runtime-semantics
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided Python reproduction under mypy --strict and compare its diagnostics with the stated Pyright behavior. Locate mypy's special handling of typing.Protocol, then add or update coverage so Protocol is accepted as a type and the reproduction produces no errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.