Skip to content

Commit 48bf3a7

Browse files
committed
inspect: Fix isgenerator logic.
Also optimise both `isgenerator()` and `isgeneratorfunction()` so they use the same lambda, and don't have to create it each time they are called. Fixes issue #997. Signed-off-by: Damien George <[email protected]>
1 parent 9307e21 commit 48bf3a7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Diff for: python-stdlib/inspect/inspect.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import sys
22

3+
_g = lambda: (yield)
4+
35

46
def getmembers(obj, pred=None):
57
res = []
@@ -16,11 +18,11 @@ def isfunction(obj):
1618

1719

1820
def isgeneratorfunction(obj):
19-
return isinstance(obj, type(lambda: (yield)))
21+
return isinstance(obj, type(_g))
2022

2123

2224
def isgenerator(obj):
23-
return isinstance(obj, type(lambda: (yield)()))
25+
return isinstance(obj, type((_g)()))
2426

2527

2628
class _Class:

0 commit comments

Comments
 (0)