From 7921b9f2104fee46413798d0a82a1e822f061957 Mon Sep 17 00:00:00 2001 From: Nick Coghlan Date: Tue, 30 Nov 2010 06:36:04 +0000 Subject: [PATCH] Issue 10220: switch to using string constants rather than integers for inspect.getgeneratorstate() return values and make debugging friendly str() and repr() for generator states a requirement in the test suite --- Lib/inspect.py | 5 ++++- Lib/test/test_inspect.py | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index e410dba61f5..ed10ac57d29 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1130,7 +1130,10 @@ def getattr_static(obj, attr, default=_sentinel): raise AttributeError(attr) -GEN_CREATED, GEN_RUNNING, GEN_SUSPENDED, GEN_CLOSED = range(4) +GEN_CREATED = 'GEN_CREATED' +GEN_RUNNING = 'GEN_RUNNING' +GEN_SUSPENDED = 'GEN_SUSPENDED' +GEN_CLOSED = 'GEN_CLOSED' def getgeneratorstate(generator): """Get current state of a generator-iterator. diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 97c47ac8df4..71f0e8aab93 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -931,6 +931,14 @@ class TestGetGeneratorState(unittest.TestCase): # Running after the first yield next(self.generator) + def test_easy_debugging(self): + # repr() and str() of a generator state should contain the state name + names = 'GEN_CREATED GEN_RUNNING GEN_SUSPENDED GEN_CLOSED'.split() + for name in names: + state = getattr(inspect, name) + self.assertIn(name, repr(state)) + self.assertIn(name, str(state)) + def test_main(): run_unittest(