7474import builtins
7575import contextlib
7676import functools
77- import inspect
7877import itertools
7978import logging
8079import re
8180import sys
8281import warnings
8382from collections import namedtuple
84- from inspect import isclass
83+ from inspect import isclass , iscoroutinefunction , isgeneratorfunction
8584from multiprocessing import current_process
8685from os .path import basename , splitext
8786from threading import current_thread
@@ -790,9 +789,7 @@ def add(
790789 encoding = getattr (sink , "encoding" , None )
791790 terminator = ""
792791 exception_prefix = "\n "
793- elif inspect .iscoroutinefunction (sink ) or inspect .iscoroutinefunction (
794- getattr (sink , "__call__" , None )
795- ):
792+ elif iscoroutinefunction (sink ) or iscoroutinefunction (getattr (sink , "__call__" , None )):
796793 name = getattr (sink , "__name__" , None ) or repr (sink )
797794
798795 if colorize is None :
@@ -807,7 +804,8 @@ def add(
807804 # running loop in Python 3.5.2 and earlier versions, see python/asyncio#452.
808805 if enqueue and loop is None :
809806 loop = asyncio .get_event_loop ()
810- coro = sink if inspect .iscoroutinefunction (sink ) else sink .__call__
807+
808+ coro = sink if iscoroutinefunction (sink ) else sink .__call__
811809 wrapped_sink = AsyncSink (coro , loop , error_interceptor )
812810 encoding = "utf8"
813811 terminator = "\n "
@@ -1201,14 +1199,14 @@ def __exit__(self_, type_, value, traceback_):
12011199 def __call__ (_ , function ):
12021200 catcher = Catcher (True )
12031201
1204- if inspect . iscoroutinefunction (function ):
1202+ if iscoroutinefunction (function ):
12051203
12061204 async def catch_wrapper (* args , ** kwargs ):
12071205 with catcher :
12081206 return await function (* args , ** kwargs )
12091207 return default
12101208
1211- elif inspect . isgeneratorfunction (function ):
1209+ elif isgeneratorfunction (function ):
12121210
12131211 def catch_wrapper (* args , ** kwargs ):
12141212 with catcher :
0 commit comments