Skip to content

Commit

Permalink
Switch plugins away from using deprecated function event.async()
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdaemon authored and daboross committed Dec 11, 2018
1 parent d059783 commit 49fa8d8
Show file tree
Hide file tree
Showing 2 changed files with 15 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
8 changes: 7 additions & 1 deletion cloudbot/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,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 49fa8d8

Please sign in to comment.