Created
February 28, 2017 21:40
-
-
Save hiway/71f87d097172343793262313482c0d05 to your computer and use it in GitHub Desktop.
Boilerplate code for iscoroutinefunction() to detect `async def`s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# $ micropython -m upip install micropython-inspect | |
try: # python 3.5+ | |
from inspect import iscoroutinefunction | |
import asyncio | |
except ImportError: # micropython 1.8+ | |
from inspect import isgeneratorfunction | |
import uasyncio as asyncio | |
def iscoroutinefunction(func): | |
return isgeneratorfunction(func) or repr(func).startswith('<closure <generator') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment