[ Web Proxy ]
URL:
Viewing: https://github-redirect.dependabot.com/python/cpython/pull/96451/files [Back]  [Original]

[3.11] gh-95987: Fix `repr` of `Any` type subclasses (GH-96412) by hauntsaninja Pull Request #96451 python/cpython GitHub
Skip to content

Navigation Menu

Sign in

Repository navigation

More items
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments. Retry
Loading
Jump to
Jump to file
Failed to load files. Retry
Loading
Diff view
[Apply and reload]
Diff view
[Apply and reload]
6 changes: 6 additions & 0 deletions Lib/test/test_typing.py
Show comments View file Edit file Delete file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ def test_any_instance_type_error(self):
def test_repr(self):
self.assertEqual(repr(Any), 'typing.Any')

class Sub(Any): pass
self.assertEqual(
repr(Sub),
"<class 'test.test_typing.AnyTests.test_repr.<locals>.Sub'>",
)

def test_errors(self):
with self.assertRaises(TypeError):
issubclass(42, Any)
Expand Down
4 changes: 3 additions & 1 deletion Lib/typing.py
Show comments View file Edit file Delete file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,9 @@ def __instancecheck__(self, obj):
return super().__instancecheck__(obj)

def __repr__(self):
return "typing.Any"
if self is Any:
return "typing.Any"
return super().__repr__() # respect to subclasses


class Any(metaclass=_AnyMeta):
Expand Down
[Go] [Go] Show comments View file Edit file Delete file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``repr`` of ``Any`` subclasses.
Toggle all file notes Toggle all file annotations

Footer

© 2026 GitHub, Inc.

Web Proxy Viewer  |  New URL  |  Original Page