Skip to content

Support ClassVar protocol members #1380

@AlexWaygood

Description

@AlexWaygood

Consider the following two protocols:

from typing import Protocol, ClassVar

class P1(Protocol):
    x: int

class P2(Protocol):
    x: ClassVar[int]

In order for a type N to satisy P1's interface, an x attribute needs to be readable with type int on instances of N and also writable with type int on instances of N. The x attribute does not need to be readable or writable on instances of type[N].

In order for a type N to satsify P2's interface, however, an s attribute needs to be readable with type int on instances of N and instances of type[N]. It does not need to be writable on instances of N, but it does need to be writable on instances of type[N].

Sub-issues

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions