# HG changeset patch # Parent 0f0645808d53aa735cb3117efe612ffc005595a8 diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1139,7 +1139,11 @@ from the specified logger to the root of the logger hierarchy. """ name = alogger.name - i = name.rfind(".") + try: + i = name.rfind(".") + except (AttributeError, TypeError): + # Not a string + i = -1 rv = None while (i > 0) and not rv: substr = name[:i] diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -3512,6 +3512,21 @@ self.addCleanup(setattr, self.logger.manager, 'disable', old_disable) self.assertFalse(self.logger.isEnabledFor(22)) + def test_exotic_names(self): + logging.Logger(any) + logging.Logger({0}) + + loggers = set() + loggers.add(logging.getLogger(all)) + loggers.add(logging.getLogger(('foo',))) + loggers.add(logging.getLogger(b'foo')) + loggers.add(logging.getLogger(True)) + self.assertEqual(len(loggers), 4) + self.assertEqual(logging.getLogger(1), logging.getLogger(True)) + + self.assertRaises(TypeError, logging.getLogger, {0}) + self.assertRaises(TypeError, logging.getLogger, bytearray(b'foo')) + class BaseFileTest(BaseTest): "Base class for handler tests that write log files"