[Python-checkins] r86879 - in python/branches/py3k/Lib: inspect.py test/test_inspect.py
nick.coghlan
python-checkins at python.org
Tue Nov 30 07:36:04 CET 2010
Author: nick.coghlan
Date: Tue Nov 30 07:36:04 2010
New Revision: 86879
Log:
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
Modified:
python/branches/py3k/Lib/inspect.py
python/branches/py3k/Lib/test/test_inspect.py
Modified: python/branches/py3k/Lib/inspect.py
==============================================================================
--- python/branches/py3k/Lib/inspect.py (original)
+++ python/branches/py3k/Lib/inspect.py Tue Nov 30 07:36:04 2010
@@ -1130,7 +1130,10 @@
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.
Modified: python/branches/py3k/Lib/test/test_inspect.py
==============================================================================
--- python/branches/py3k/Lib/test/test_inspect.py (original)
+++ python/branches/py3k/Lib/test/test_inspect.py Tue Nov 30 07:36:04 2010
@@ -931,6 +931,14 @@
# 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(
More information about the Python-checkins
mailing list