Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Gobot1234 opened this issue Aug 14, 2022 · 2 comments
Labels
3.11 only security fixes 3.12 bugs and security fixes stdlib Python modules in the Lib dir topic-typing type-bug An unexpected behavior, bug, or error

Comments

@Gobot1234
Copy link
Contributor

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
@Gobot1234 Gobot1234 added the type-bug An unexpected behavior, bug, or error label Aug 14, 2022
@AlexWaygood AlexWaygood added topic-typing stdlib Python modules in the Lib dir 3.11 only security fixes 3.12 bugs and security fixes labels Aug 14, 2022
@hauntsaninja
Copy link
Contributor

hauntsaninja commented Aug 15, 2022

Yup, good catch, sounds right!

@Gobot1234
Copy link
Contributor Author

Fixed by #96412

hauntsaninja pushed a commit to hauntsaninja/cpython that referenced this issue Aug 31, 2022
…96412)

(cherry picked from commit 4217393)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
ambv pushed a commit that referenced this issue Oct 5, 2022
(cherry picked from commit 4217393)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes 3.12 bugs and security fixes stdlib Python modules in the Lib dir topic-typing type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants