Skip to content

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

Description

@Gobot1234

Bug report

from typing import Any

class Foo(Any): ...

print(repr(Foo))  # => typing.Any not <class '__main__.Foo'> as I would expect

I believe

cpython/Lib/typing.py

Lines 495 to 496 in e8259e0

def __repr__(self):
return "typing.Any"
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

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    3.11only security fixes
    3.12only security fixes
    on Aug 14, 2022
  2. hauntsaninja commented on Aug 15, 2022

    @hauntsaninja
    Contributor

    Yup, good catch, sounds right!

  3. added a commit that references this issue on Aug 30, 2022
  4. added a commit that references this issue on Aug 30, 2022
  5. Gobot1234 commented on Aug 31, 2022

    @Gobot1234
    ContributorAuthor

    Fixed by #96412

  6. added a commit that references this issue on Aug 31, 2022
  7. added a commit that references this issue on Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions