mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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:
parent
1092cfb201
commit
623b338adf
7 changed files with 58 additions and 19 deletions
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue