Skip to content

Difference between builtins.type and Type[Any] #12933

@harahu

Description

@harahu

Bug Report

I have a protocol:

class SupportsStr(Protocol):
    def __str__(self) -> str:
        ...

Surprisingly, builtins.type is compliant with this, while Type[Any] isn't.

To Reproduce

Link to mypy playground: https://mypy-play.net/?mypy=latest&python=3.11&gist=355a1b96812a523f6e374eb8ca6f4635

Expected Behavior

I would think both should be compliant, given that the typing.Type docs states that:

Type[Any] is equivalent to Type which in turn is equivalent to type, which is the root of Python’s metaclass hierarchy.

Actual Behavior

Surprisingly, builtins.type is compliant with this, while Type[Any] isn't.

Your Environment

See link to mypy playground.

Mypy 0.960 and python 3.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-pep-585PEP 585 (builtin generics)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions