cpython icon indicating copy to clipboard operation
cpython copied to clipboard

repr(subclass of typing.Any) shows typing.Any not <__main__.subclass of typing.Any>

Open Gobot1234 opened this issue 3 years ago • 1 comments

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

Gobot1234 avatar Aug 14 '22 22:08 Gobot1234

Yup, good catch, sounds right!

hauntsaninja avatar Aug 15 '22 05:08 hauntsaninja

Fixed by #96412

Gobot1234 avatar Aug 31 '22 00:08 Gobot1234