Skip to content

Protocols are not recognised as such if declared together with Generic[T] #7381

@ilevkivskyi

Description

@ilevkivskyi

This test case:

[case testRuntimeProtoTwoBases]
from typing_extensions import Protocol, runtime_checkable
from typing import TypeVar, Generic

T = TypeVar('T')

@runtime_checkable
class P(Protocol, Generic[T]):
    attr: T

class C:
    attr: int

x: P[int] = C()

fails with

main:7: error: @runtime_checkable can only be used with protocol classes
main:13: error: Incompatible types in assignment (expression has type "C", variable has type "P[int]")

Both replacing Protocol, Generic[T] with Protocol[T], and changing the order of bases to Generic[T], Protocol fixes the issue.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions