|
2 | 2 | import concurrent.futures |
3 | 3 | import enum |
4 | 4 | import logging |
| 5 | +import warnings |
| 6 | +from functools import partial |
| 7 | + |
| 8 | +import sys |
5 | 9 |
|
6 | 10 | logger = logging.getLogger("cloudbot") |
7 | 11 |
|
@@ -310,17 +314,27 @@ def has_permission(self, permission, notice=True): |
310 | 314 | return self.conn.permissions.has_perm_mask(self.mask, permission, notice=notice) |
311 | 315 |
|
312 | 316 | @asyncio.coroutine |
313 | | - def async(self, function, *args, **kwargs): |
| 317 | + def async_call(self, func, *args, **kwargs): |
314 | 318 | if self.db_executor is not None: |
315 | 319 | executor = self.db_executor |
316 | 320 | else: |
317 | 321 | 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) |
322 | 325 | return result |
323 | 326 |
|
| 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 | + |
324 | 338 |
|
325 | 339 | class CommandEvent(Event): |
326 | 340 | """ |
|
0 commit comments