Skip to content

Instance attributes specified in protocols should not be usable as class attributes in inheriting concrete classes #9118

@eguiraud

Description

@eguiraud

Are you reporting a bug, or opening a feature request?

Bug

Minimal repro

from typing import Protocol

class SomeProtocol(Protocol):
    y : int
    x : int = 3

class Class(SomeProtocol):
    pass

def test1() -> None:
    y: int = Class.y  # runtime error. mypy should catch it?

def test2() -> None:
    x: int = Class.x  # runs fine, but should probably be a mypy error?

What is the actual behavior/output?

mypy reports no errors.

What is the behavior/output you expect?

I would expect mypy to complain that Class does not have class attributes x nor y (they are not marked with ClassVar).

What are the versions of mypy and Python you are using?

mypy: 0.782
python: 3.8.3

What are the mypy flags you are using? (For example --strict-optional)

No flags

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions