]> granicus.if.org Git - python/commitdiff
Issue 10220: switch to using string constants rather than integers for inspect.getgen...
authorNick Coghlan <ncoghlan@gmail.com>
Tue, 30 Nov 2010 06:36:04 +0000 (06:36 +0000)
committerNick Coghlan <ncoghlan@gmail.com>
Tue, 30 Nov 2010 06:36:04 +0000 (06:36 +0000)
Lib/inspect.py
Lib/test/test_inspect.py

index e410dba61f540a678fd2dd5af77a9e01d7669ba4..ed10ac57d29f96e9370fbbdc7c4d4b6fb5fcc686 100644 (file)
@@ -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.
index 97c47ac8df468f044517fffd4a71b0d06029c73f..71f0e8aab93009ffe99a04d112bde23163b5234f 100644 (file)
@@ -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(