Skip to content

Commit ca87eeb

Browse files
xrmxvsajip
authored andcommitted
bpo-36015: Handle StreamHandler representaton of stream with an integer name (GH-11908)
1 parent 3918ad6 commit ca87eeb

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

Lib/logging/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,8 @@ def setStream(self, stream):
11111111
def __repr__(self):
11121112
level = getLevelName(self.level)
11131113
name = getattr(self.stream, 'name', '')
1114+
# bpo-36015: name can be an int
1115+
name = str(name)
11141116
if name:
11151117
name += ' '
11161118
return '<%s %s(%s)>' % (self.__class__.__name__, name, level)

Lib/test/test_logging.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,10 @@ class TestStreamHandler(logging.StreamHandler):
760760
def handleError(self, record):
761761
self.error_record = record
762762

763+
class StreamWithIntName(object):
764+
level = logging.NOTSET
765+
name = 2
766+
763767
class StreamHandlerTest(BaseTest):
764768
def test_error_handling(self):
765769
h = TestStreamHandler(BadStream())
@@ -797,6 +801,10 @@ def test_stream_setting(self):
797801
actual = h.setStream(old)
798802
self.assertIsNone(actual)
799803

804+
def test_can_represent_stream_with_int_name(self):
805+
h = logging.StreamHandler(StreamWithIntName())
806+
self.assertEqual(repr(h), '<StreamHandler 2 (NOTSET)>')
807+
800808
# -- The following section could be moved into a server_helper.py module
801809
# -- if it proves to be of wider utility than just test_logging
802810

0 commit comments

Comments
 (0)