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>
pull/998/head
Damien George 2025-04-11 12:23:33 +10:00
rodzic 9307e21dfb
commit 48bf3a74a8
1 zmienionych plików z 4 dodań i 2 usunięć

Wyświetl plik

@ -1,5 +1,7 @@
import sys
_g = lambda: (yield)
def getmembers(obj, pred=None):
res = []
@ -16,11 +18,11 @@ def isfunction(obj):
def isgeneratorfunction(obj):
return isinstance(obj, type(lambda: (yield)))
return isinstance(obj, type(_g))
def isgenerator(obj):
return isinstance(obj, type(lambda: (yield)()))
return isinstance(obj, type((_g)()))
class _Class: