diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-12-02 21:39:56 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-12-02 21:39:56 (GMT) |
commit | 4954f9fcab59e38f2229998b3276567d4bf92b53 (patch) | |
tree | 5f0e1732e20489b9a6843ba6e742e9a84a393c49 | |
parent | b16edc8087586699e775d6fa6b20d750e9916fff (diff) | |
download | cpython-4954f9fcab59e38f2229998b3276567d4bf92b53.zip cpython-4954f9fcab59e38f2229998b3276567d4bf92b53.tar.gz cpython-4954f9fcab59e38f2229998b3276567d4bf92b53.tar.bz2 |
Issue #17401: Output the closefd attribute as boolean.
-rw-r--r-- | Lib/test/test_fileio.py | 18 | ||||
-rw-r--r-- | Modules/_io/fileio.c | 8 |
2 files changed, 18 insertions, 8 deletions
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py index 7c1a5ce..743ca5c 100644 --- a/Lib/test/test_fileio.py +++ b/Lib/test/test_fileio.py @@ -113,15 +113,25 @@ class AutoFileTests(unittest.TestCase): def testRepr(self): self.assertEqual( - repr(self.f), "<_io.FileIO name=%r mode=%r closefd='%d'>" - % (self.f.name, self.f.mode, self.f.closefd)) + repr(self.f), "<_io.FileIO name=%r mode=%r closefd=True>" + % (self.f.name, self.f.mode)) del self.f.name self.assertEqual( - repr(self.f), "<_io.FileIO fd=%r mode=%r closefd='%d'>" - % (self.f.fileno(), self.f.mode, self.f.closefd)) + repr(self.f), "<_io.FileIO fd=%r mode=%r closefd=True>" + % (self.f.fileno(), self.f.mode)) self.f.close() self.assertEqual(repr(self.f), "<_io.FileIO [closed]>") + def testReprNoCloseFD(self): + fd = os.open(TESTFN, os.O_RDONLY) + try: + with _FileIO(fd, 'r', closefd=False) as f: + self.assertEqual(repr(f), + "<_io.FileIO name=%r mode=%r closefd=False>" + % (f.name, f.mode)) + finally: + os.close(fd) + def testErrors(self): f = self.f self.assertTrue(not f.isatty()) diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index 5c1316e..80af83a 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -1055,13 +1055,13 @@ fileio_repr(fileio *self) else return NULL; res = PyUnicode_FromFormat( - "<_io.FileIO fd=%d mode='%s' closefd='%d'>", - self->fd, mode_string(self), self->closefd); + "<_io.FileIO fd=%d mode='%s' closefd=%s>", + self->fd, mode_string(self), self->closefd ? "True" : "False"); } else { res = PyUnicode_FromFormat( - "<_io.FileIO name=%R mode='%s' closefd='%d'>", - nameobj, mode_string(self), self->closefd); + "<_io.FileIO name=%R mode='%s' closefd=%s>", + nameobj, mode_string(self), self->closefd ? "True" : "False"); Py_DECREF(nameobj); } return res; |