[Python-checkins] bpo-36015: Handle StreamHandler representaton of stream with an integer name (GH-11908) (GH-13183)
Vinay Sajip
webhook-mailer at python.org
Wed May 15 14:06:42 EDT 2019
https://github.com/python/cpython/commit/78dd781ef4d41dfefad53aa3bc52c39b0d443b19
commit: 78dd781ef4d41dfefad53aa3bc52c39b0d443b19
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Vinay Sajip <vinay_sajip at yahoo.co.uk>
date: 2019-05-15T19:06:29+01:00
summary:
bpo-36015: Handle StreamHandler representaton of stream with an integer name (GH-11908) (GH-13183)
(cherry picked from commit ca87eebb22d202c33f3317cbf85059cadc64fa9f)
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti at gmail.com>
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 cd80d5cccc6e..6e017148861d 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -1055,6 +1055,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 14277369be47..d12e1e57455d 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -766,6 +766,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())
@@ -803,6 +807,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