Skip to content

Commit 1c4499e

Browse files
committed
Deprecate event.async() in favor of event.async_call()due to changes in 3.7.0
1 parent 2aa5ff7 commit 1c4499e

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

cloudbot/event.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
import concurrent.futures
33
import enum
44
import logging
5+
import warnings
6+
from functools import partial
7+
8+
import sys
59

610
logger = logging.getLogger("cloudbot")
711

@@ -310,17 +314,27 @@ def has_permission(self, permission, notice=True):
310314
return self.conn.permissions.has_perm_mask(self.mask, permission, notice=notice)
311315

312316
@asyncio.coroutine
313-
def async(self, function, *args, **kwargs):
317+
def async_call(self, func, *args, **kwargs):
314318
if self.db_executor is not None:
315319
executor = self.db_executor
316320
else:
317321
executor = None
318-
if kwargs:
319-
result = yield from self.loop.run_in_executor(executor, function, *args)
320-
else:
321-
result = yield from self.loop.run_in_executor(executor, lambda: function(*args, **kwargs))
322+
323+
part = partial(func, *args, **kwargs)
324+
result = yield from self.loop.run_in_executor(executor, part)
322325
return result
323326

327+
if sys.version_info < (3, 7, 0):
328+
# noinspection PyCompatibility
329+
@asyncio.coroutine
330+
def async(self, function, *args, **kwargs):
331+
warnings.warn(
332+
"event.async() is deprecated, use event.async_call() instead.",
333+
DeprecationWarning, stacklevel=2
334+
)
335+
result = yield from self.async_call(function, *args, **kwargs)
336+
return result
337+
324338

325339
class CommandEvent(Event):
326340
"""

0 commit comments

Comments
 (0)