cpython
cpython copied to clipboard
repr(subclass of typing.Any) shows typing.Any not <__main__.subclass of typing.Any>
Bug report
from typing import Any
class Foo(Any): ...
print(repr(Foo)) # => typing.Any not <class '__main__.Foo'> as I would expect
I believe https://github.com/python/cpython/blob/e8259e047c42976427b08f100b9d8ba52db7ee69/Lib/typing.py#L495-L496 needs to be changed to
def __repr__(self):
if self is Any:
return "typing.Any"
return super().__repr__()
Your environment
- CPython versions tested on: 3.11 and 3.12
- Operating system and architecture: macOS
Yup, good catch, sounds right!
Fixed by #96412