Difference between `builtins.type` and `Type[Any]`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the discrepancy in the linked mypy playground, comparing builtins.type with Type[Any] under the stated Python and mypy versions. Trace how each type is interpreted for the SupportsStr protocol and consider the documented equivalence; done means the behavior is consistent with that expectation and covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100