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 <damien@micropython.org>
1 parent 9307e21 commit 48bf3a7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

python-stdlib/inspect/inspect.py

Lines changed: 4 additions & 2 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy