diff -r 9d4e0445cdce Lib/enum.py --- a/Lib/enum.py Thu Oct 03 14:39:39 2013 -0600 +++ b/Lib/enum.py Thu Oct 03 23:00:36 2013 +0100 @@ -15,14 +15,16 @@ def _is_dunder(name): """Returns True if a __dunder__ name, False otherwise.""" - return (name[:2] == name[-2:] == '__' and + return (len(name) > 4 and + name[:2] == name[-2:] == '__' and name[2:3] != '_' and name[-3:-2] != '_') def _is_sunder(name): """Returns True if a _sunder_ name, False otherwise.""" - return (name[0] == name[-1] == '_' and + return (len(name) > 2 and + name[0] == name[-1] == '_' and name[1:2] != '_' and name[-2:-1] != '_') diff -r 9d4e0445cdce Lib/test/test_enum.py --- a/Lib/test/test_enum.py Thu Oct 03 14:39:39 2013 -0600 +++ b/Lib/test/test_enum.py Thu Oct 03 23:00:36 2013 +0100 @@ -58,6 +58,39 @@ except Exception: pass + +class TestHelpers(unittest.TestCase): + """ + _is_descriptor + _is_sunder + _is_dunder + + Are private helper methods enforcing naming syntax. + """ + + def test_is_descriptor(self): + class foo: + pass + for attr in ('__get__','__set__','__delete__'): + obj = foo() + self.assertFalse(enum._is_descriptor(obj)) + setattr(obj, attr, 1) + self.assertTrue(enum._is_descriptor(obj)) + + def test_is_sunder(self): + for s in '_a_ _aa_'.split(): + self.assertTrue(enum._is_sunder(s)) + + for s in 'a a_ _a __a a__ __a__ _a__ __a_ _ __ ___'.split(): + self.assertFalse(enum._is_sunder(s)) + + def test_is_dunder(self): + for s in '__a__ __aa__'.split(): + assert enum._is_dunder(s) + + for s in 'a a_ a__ __a __a_ _ __ ___'.split(): + assert not enum._is_dunder(s) + class TestEnum(unittest.TestCase): def setUp(self): class Season(Enum):