diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2022-08-30 17:36:16 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-30 17:36:16 (GMT) |
commit | 4217393aeed42d67dd4b16a128528f5ca8d939c4 (patch) | |
tree | ce66e2cf6cc4cd318b1eaaf77d7e6984fb80b192 /Lib | |
parent | 6d791a97364b68d5f9c3514a0470aac487fc538d (diff) | |
download | cpython-4217393aeed42d67dd4b16a128528f5ca8d939c4.zip cpython-4217393aeed42d67dd4b16a128528f5ca8d939c4.tar.gz cpython-4217393aeed42d67dd4b16a128528f5ca8d939c4.tar.bz2 |
gh-95987: Fix `repr` of `Any` type subclasses (#96412)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_typing.py | 6 | ||||
-rw-r--r-- | Lib/typing.py | 4 |
2 files changed, 9 insertions, 1 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 7eea019..9239673 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -113,6 +113,12 @@ class AnyTests(BaseTestCase): 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) diff --git a/Lib/typing.py b/Lib/typing.py index 596744e..84fe007 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -493,7 +493,9 @@ class _AnyMeta(type): 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): |