kopia lustrzana https://github.com/micropython/micropython-lib
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
rodzic
9307e21dfb
commit
48bf3a74a8
|
@ -1,5 +1,7 @@
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
_g = lambda: (yield)
|
||||||
|
|
||||||
|
|
||||||
def getmembers(obj, pred=None):
|
def getmembers(obj, pred=None):
|
||||||
res = []
|
res = []
|
||||||
|
@ -16,11 +18,11 @@ def isfunction(obj):
|
||||||
|
|
||||||
|
|
||||||
def isgeneratorfunction(obj):
|
def isgeneratorfunction(obj):
|
||||||
return isinstance(obj, type(lambda: (yield)))
|
return isinstance(obj, type(_g))
|
||||||
|
|
||||||
|
|
||||||
def isgenerator(obj):
|
def isgenerator(obj):
|
||||||
return isinstance(obj, type(lambda: (yield)()))
|
return isinstance(obj, type((_g)()))
|
||||||
|
|
||||||
|
|
||||||
class _Class:
|
class _Class:
|
||||||
|
|
Ładowanie…
Reference in New Issue