diff options
-rw-r--r-- | Doc/lib/libtypes.tex | 6 | ||||
-rw-r--r-- | Lib/test/test_generators.py | 20 | ||||
-rw-r--r-- | Lib/types.py | 5 |
3 files changed, 31 insertions, 0 deletions
diff --git a/Doc/lib/libtypes.tex b/Doc/lib/libtypes.tex index 8ade4a6..35495eb 100644 --- a/Doc/lib/libtypes.tex +++ b/Doc/lib/libtypes.tex @@ -83,6 +83,12 @@ The type of user-defined functions and lambdas. An alternate name for \code{FunctionType}. \end{datadesc} +\begin{datadesc}{GeneratorType} +The type of generator-iterator objects, produced by calling a +generator function. +\versionadded{2.2} +\end{datadesc} + \begin{datadesc}{CodeType} The type for code objects such as returned by \function{compile()}\bifuncindex{compile}. diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py index e0d6cfa..884cbc0 100644 --- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -367,6 +367,26 @@ Next one was posted to c.l.py. 4-combs of [1, 2, 3, 4]: [1, 2, 3, 4] 5-combs of [1, 2, 3, 4]: + +# From the Iterators list, about the types of these things. + +>>> def g(): +... yield 1 +... +>>> type(g) +<type 'function'> +>>> i = g() +>>> type(i) +<type 'generator'> +>>> dir(i) +['next'] +>>> print i.next.__doc__ +next() -- get the next value, or raise StopIteration +>>> iter(i) is i +1 +>>> import types +>>> isinstance(i, types.GeneratorType) +1 """ # Fun tests (for sufficiently warped notions of "fun"). diff --git a/Lib/types.py b/Lib/types.py index a71a4db..85962ba 100644 --- a/Lib/types.py +++ b/Lib/types.py @@ -32,6 +32,11 @@ try: except: pass +def g(): + yield 1 +GeneratorType = type(g()) +del g + class _C: def _m(self): pass ClassType = type(_C) |