Skip to content

Commit 78dd781

Browse files
miss-islingtonxrmx
authored andcommitted
bpo-36015: Handle StreamHandler representaton of stream with an integer name (GH-11908) (GH-13183)
(cherry picked from commit ca87eeb) Co-authored-by: Riccardo Magliocchetti <[email protected]>
1 parent 4fd7f56 commit 78dd781

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
@@ -1055,6 +1055,8 @@ def setStream(self, stream):
10551055
def __repr__(self):
10561056
level = getLevelName(self.level)
10571057
name = getattr(self.stream, 'name', '')
1058+
# bpo-36015: name can be an int
1059+
name = str(name)
10581060
if name:
10591061
name += ' '
10601062
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
@@ -766,6 +766,10 @@ class TestStreamHandler(logging.StreamHandler):
766766
def handleError(self, record):
767767
self.error_record = record
768768

769+
class StreamWithIntName(object):
770+
level = logging.NOTSET
771+
name = 2
772+
769773
class StreamHandlerTest(BaseTest):
770774
def test_error_handling(self):
771775
h = TestStreamHandler(BadStream())
@@ -803,6 +807,10 @@ def test_stream_setting(self):
803807
actual = h.setStream(old)
804808
self.assertIsNone(actual)
805809

810+
def test_can_represent_stream_with_int_name(self):
811+
h = logging.StreamHandler(StreamWithIntName())
812+
self.assertEqual(repr(h), '<StreamHandler 2 (NOTSET)>')
813+
806814
# -- The following section could be moved into a server_helper.py module
807815
# -- if it proves to be of wider utility than just test_logging
808816

0 commit comments

Comments
 (0)