StreamLogWriter: Provide (no-op) close method. (#10884)

Some contexts try to close their reference to the stderr stream at logging shutdown, this ensures these don't break.

* Make pylint happy

An explicit `pass` is better here, but the docstring _is_ a statement.

Co-authored-by: Ash Berlin-Taylor <ash_github@firemirror.com>
This commit is contained in:
Martijn Pieters 2020-10-20 09:20:39 +01:00 коммит произвёл GitHub
Родитель 3ee618623b
Коммит 26ae8e93e8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 14 добавлений и 0 удалений

Просмотреть файл

@ -93,6 +93,13 @@ class StreamLogWriter:
self.level = level
self._buffer = ''
def close(self):
"""
Provide close method, for compatibility with the io.IOBase interface.
This is a no-op method.
"""
@property
def closed(self): # noqa: D402
"""

Просмотреть файл

@ -96,3 +96,10 @@ class TestStreamLogWriter(unittest.TestCase):
log = StreamLogWriter(logger, 1)
self.assertIsNone(log.encoding)
def test_iobase_compatibility(self):
log = StreamLogWriter(None, 1)
self.assertFalse(log.closed)
# has no specific effect
log.close()