From: Vinay Sajip Date: Wed, 11 Jan 2017 06:57:55 +0000 (+0000) Subject: Closes #29220: Fixed regression in logging.getLevelName(). X-Git-Tag: v3.7.0a1~1583 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8b866d5429c72227a6133d6964b9800a184556fd;p=python Closes #29220: Fixed regression in logging.getLevelName(). --- diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index d886d35c12..fb866f39d9 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -131,9 +131,13 @@ def getLevelName(level): Otherwise, the string "Level %s" % level is returned. """ - # See Issues #22386 and #27937 for why it's this way - return (_levelToName.get(level) or _nameToLevel.get(level) or - "Level %s" % level) + # See Issues #22386, #27937 and #29220 for why it's this way + result = _levelToName.get(level) + if result is None: + result = _nameToLevel.get(level) + if result is None: + result = "Level %s" % level + return result def addLevelName(level, levelName): """ diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index d5981e8ab8..6a911528c7 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -309,6 +309,12 @@ class BuiltinLevelsTest(BaseTest): self.assertEqual(logging.getLevelName('INFO'), logging.INFO) self.assertEqual(logging.getLevelName(logging.INFO), 'INFO') + def test_regression_29220(self): + """See issue #29220 for more information.""" + logging.addLevelName(logging.INFO, '') + self.addCleanup(logging.addLevelName, logging.INFO, 'INFO') + self.assertEqual(logging.getLevelName(logging.INFO), '') + def test_issue27935(self): fatal = logging.getLevelName('FATAL') self.assertEqual(fatal, logging.FATAL)