Skip to content

Commit b251c59

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 micropython#997. Signed-off-by: Damien George <[email protected]>
1 parent 98d0a2b commit b251c59

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
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:

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
metadata(version="0.1.2")
1+
metadata(version="0.1.3")
22

33
module("inspect.py")

0 commit comments

Comments
 (0)