[Python-checkins] bpo-36015: Handle StreamHandler representaton of stream with an integer name (GH-11908)
Vinay Sajip
webhook-mailer at python.org
Tue May 7 17:36:43 EDT 2019
https://github.com/python/cpython/commit/ca87eebb22d202c33f3317cbf85059cadc64fa9f
commit: ca87eebb22d202c33f3317cbf85059cadc64fa9f
branch: master
author: Riccardo Magliocchetti <riccardo.magliocchetti at gmail.com>
committer: Vinay Sajip <vinay_sajip at yahoo.co.uk>
date: 2019-05-07T22:36:39+01:00
summary:
bpo-36015: Handle StreamHandler representaton of stream with an integer name (GH-11908)
files:
M Lib/logging/__init__.py
M Lib/test/test_logging.py
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 07a0c0c4ae98..16812ec8d556 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -1111,6 +1111,8 @@ def setStream(self, stream):
def __repr__(self):
level = getLevelName(self.level)
name = getattr(self.stream, 'name', '')
+ # bpo-36015: name can be an int
+ name = str(name)
if name:
name += ' '
return '<%s %s(%s)>' % (self.__class__.__name__, name, level)
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 950217cec288..bc99c3adbe34 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -760,6 +760,10 @@ class TestStreamHandler(logging.StreamHandler):
def handleError(self, record):
self.error_record = record
+class StreamWithIntName(object):
+ level = logging.NOTSET
+ name = 2
+
class StreamHandlerTest(BaseTest):
def test_error_handling(self):
h = TestStreamHandler(BadStream())
@@ -797,6 +801,10 @@ def test_stream_setting(self):
actual = h.setStream(old)
self.assertIsNone(actual)
+ def test_can_represent_stream_with_int_name(self):
+ h = logging.StreamHandler(StreamWithIntName())
+ self.assertEqual(repr(h), '<StreamHandler 2 (NOTSET)>')
+
# -- The following section could be moved into a server_helper.py module
# -- if it proves to be of wider utility than just test_logging
More information about the Python-checkins
mailing list