Skip to content

Disallow type(x) if x has a protocol type #16919

@JukkaL

Description

@JukkaL

Modules can implement protocols, so type(x) is not necessarily a type object if x has a protocol type.

from typing import Protocol class P(Protocol): def f(self) -> None: ... def f(p: P) -> None: reveal_type(type(p)) # type[P] (incorrect!)

It's probably best to to generate an error if type is called on an object with a protocol type, as suggested by @hauntsaninja in #16890 (comment).

See #16890 for more context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions