Skip to content

Commit

Permalink
Further fix async stuff for python3.7 compat.
Browse files Browse the repository at this point in the history
This takes from snoonetIRC@899cd32

A proper git merge worked this time, so the author is correctly
attributed.

Merge branch 'async-fix-from-snoonetirc'
  • Loading branch information
daboross committed Dec 11, 2018
2 parents d059783 + 5c2d9fc commit 6c5a88f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion cloudbot/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def async_call(self, function, *args, **kwargs):
if sys.version_info < (3, 7, 0):
# noinspection PyCompatibility
@asyncio.coroutine
def async(self, func, *args, **kwargs):
def async_(self, func, *args, **kwargs):
warnings.warn(
"event.async() is deprecated, use event.async_call() instead.",
DeprecationWarning,
Expand All @@ -334,6 +334,13 @@ def async(self, func, *args, **kwargs):
return result


# Silence deprecation warnings about use of the 'async' name as a function
try:
setattr(Event, 'async', getattr(Event, 'async_'))
except AttributeError:
pass


class CommandEvent(Event):
"""
:type hook: cloudbot.plugin.CommandHook
Expand Down
9 changes: 8 additions & 1 deletion cloudbot/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import os
import re
import sys

import sqlalchemy

Expand Down Expand Up @@ -570,7 +571,13 @@ def __init__(self, _type, plugin, func_hook):

# don't process args starting with "_"
self.required_args = [arg for arg in self.required_args if not arg.startswith("_")]

if sys.version_info < (3, 7, 0):
if "async" in self.required_args:
logger.warning("Use of deprecated function 'async' in %s", self.description)
warnings.warn(
"event.async() is deprecated, use event.async_call() instead.",
DeprecationWarning, stacklevel=2
)
if asyncio.iscoroutine(self.function) or asyncio.iscoroutinefunction(self.function):
self.threaded = False
else:
Expand Down

0 comments on commit 6c5a88f

Please sign in to comment.