diff options
author | AN Long <aisk@users.noreply.github.com> | 2024-01-09 20:39:36 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-09 20:39:36 (GMT) |
commit | 623b338adf2645b09c546e7a17f2648d3a900620 (patch) | |
tree | 2c449075d2ce13ac8d6affe944632d1ac94f2339 /Lib | |
parent | 1092cfb20179ac7dd6a2c3c6f8a57ecc1732c777 (diff) | |
download | cpython-623b338adf2645b09c546e7a17f2648d3a900620.zip cpython-623b338adf2645b09c546e7a17f2648d3a900620.tar.gz cpython-623b338adf2645b09c546e7a17f2648d3a900620.tar.bz2 |
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
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_fileio.py | 10 | ||||
-rw-r--r-- | Lib/test/test_io.py | 7 | ||||
-rw-r--r-- | Lib/test/test_winconsoleio.py | 10 |
3 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py index f490485..06d9b45 100644 --- a/Lib/test/test_fileio.py +++ b/Lib/test/test_fileio.py @@ -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: diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index ca31b9d..936edea 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -2806,6 +2806,13 @@ class TextIOWrapperTest(unittest.TestCase): with self.assertRaises(RuntimeError): repr(t) # Should not crash + def test_subclass_repr(self): + class TestSubclass(self.TextIOWrapper): + pass + + f = TestSubclass(self.StringIO()) + self.assertIn(TestSubclass.__name__, repr(f)) + def test_line_buffering(self): r = self.BytesIO() b = self.BufferedWriter(r, 1000) diff --git a/Lib/test/test_winconsoleio.py b/Lib/test/test_winconsoleio.py index 70a8555..72ff960 100644 --- a/Lib/test/test_winconsoleio.py +++ b/Lib/test/test_winconsoleio.py @@ -98,6 +98,16 @@ class WindowsConsoleIOTests(unittest.TestCase): self.assertIsInstance(f, ConIO) f.close() + def test_subclass_repr(self): + class TestSubclass(ConIO): + pass + + f = TestSubclass("CON") + with f: + self.assertIn(TestSubclass.__name__, repr(f)) + + self.assertIn(TestSubclass.__name__, repr(f)) + @unittest.skipIf(sys.getwindowsversion()[:2] <= (6, 1), "test does not work on Windows 7 and earlier") def test_conin_conout_names(self): |