gh-66060: Use actual class name in _io type's __repr__ (#30824)

Use the object's actual class name in the following _io type's __repr__:
- FileIO
- TextIOWrapper
- _WindowsConsoleIO
This commit is contained in:
AN Long 2024-01-10 04:39:36 +08:00 committed by GitHub
parent 1092cfb201
commit 623b338adf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 58 additions and 19 deletions

View file

@ -174,6 +174,16 @@ class AutoFileTests:
self.assertEqual(repr(self.f),
"<%s.FileIO [closed]>" % (self.modulename,))
def test_subclass_repr(self):
class TestSubclass(self.FileIO):
pass
f = TestSubclass(TESTFN)
with f:
self.assertIn(TestSubclass.__name__, repr(f))
self.assertIn(TestSubclass.__name__, repr(f))
def testReprNoCloseFD(self):
fd = os.open(TESTFN, os.O_RDONLY)
try: