Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8b866d5

Browse files
committed
Closes #29220: Fixed regression in logging.getLevelName().
1 parent 231d1f3 commit 8b866d5

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

Lib/logging/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,13 @@ def getLevelName(level):
131131
132132
Otherwise, the string "Level %s" % level is returned.
133133
"""
134-
# See Issues #22386 and #27937 for why it's this way
135-
return (_levelToName.get(level) or _nameToLevel.get(level) or
136-
"Level %s" % level)
134+
# See Issues #22386, #27937 and #29220 for why it's this way
135+
result = _levelToName.get(level)
136+
if result is None:
137+
result = _nameToLevel.get(level)
138+
if result is None:
139+
result = "Level %s" % level
140+
return result
137141

138142
def addLevelName(level, levelName):
139143
"""

Lib/test/test_logging.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,12 @@ def test_regression_22386(self):
309309
self.assertEqual(logging.getLevelName('INFO'), logging.INFO)
310310
self.assertEqual(logging.getLevelName(logging.INFO), 'INFO')
311311

312+
def test_regression_29220(self):
313+
"""See issue #29220 for more information."""
314+
logging.addLevelName(logging.INFO, '')
315+
self.addCleanup(logging.addLevelName, logging.INFO, 'INFO')
316+
self.assertEqual(logging.getLevelName(logging.INFO), '')
317+
312318
def test_issue27935(self):
313319
fatal = logging.getLevelName('FATAL')
314320
self.assertEqual(fatal, logging.FATAL)

0 commit comments

Comments
 (0)