diff --git a/beets/plugins.py b/beets/plugins.py index 7019b70a0..5ca9ae3bb 100644 --- a/beets/plugins.py +++ b/beets/plugins.py @@ -19,6 +19,7 @@ from __future__ import division, absolute_import, print_function import traceback import re +import inspect from collections import defaultdict from functools import wraps @@ -26,7 +27,6 @@ from functools import wraps import beets from beets import logging from beets import mediafile -from beets.util import inspect import six PLUGIN_NAMESPACE = 'beetsplug' @@ -127,7 +127,10 @@ class BeetsPlugin(object): value after the function returns). Also determines which params may not be sent for backwards-compatibility. """ - argspec = inspect.getargspec(func) + if six.PY2: + func_args = inspect.getargspec(func).args + else: + func_args = inspect.getfullargspec(func).args @wraps(func) def wrapper(*args, **kwargs): @@ -142,7 +145,7 @@ class BeetsPlugin(object): if exc.args[0].startswith(func.__name__): # caused by 'func' and not stuff internal to 'func' kwargs = dict((arg, val) for arg, val in kwargs.items() - if arg in argspec.args) + if arg in func_args) return func(*args, **kwargs) else: raise diff --git a/beets/util/inspect.py b/beets/util/inspect.py deleted file mode 100644 index b90c0fe45..000000000 --- a/beets/util/inspect.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- coding: utf-8 -*- -# This file is part of beets. -# Copyright 2019, Vladimir Zhelezov. -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. - -from __future__ import division, absolute_import, print_function - -import inspect - -from six import PY2 - - -def getargspec(func): - if PY2: - return inspect.getargspec(func) - return inspect.getfullargspec(func) diff --git a/beetsplug/bpd/__init__.py b/beetsplug/bpd/__init__.py index 086af21b3..c8fc10509 100644 --- a/beetsplug/bpd/__init__.py +++ b/beetsplug/bpd/__init__.py @@ -26,12 +26,13 @@ import traceback import random import time import math +import inspect import beets from beets.plugins import BeetsPlugin import beets.ui from beets import vfs -from beets.util import bluelet, inspect +from beets.util import bluelet from beets.library import Item from beets import dbcore from beets.mediafile import MediaFile @@ -749,7 +750,13 @@ class Command(object): raise BPDError(ERROR_UNKNOWN, u'unknown command "{}"'.format(self.name)) func = getattr(conn.server, func_name) - argspec = inspect.getargspec(func) + + if six.PY2: + # caution: the fields of the namedtuple are slightly different + argspec = inspect.getargspec(func) + else: + argspec = inspect.getfullargspec(func) + max_args = len(argspec.args) - 2 min_args = max_args if argspec.defaults: diff --git a/test/test_plugins.py b/test/test_plugins.py index 7c32e9aca..b14158699 100644 --- a/test/test_plugins.py +++ b/test/test_plugins.py @@ -322,7 +322,7 @@ class ListenersTest(unittest.TestCase, TestHelper): @patch('beets.plugins.find_plugins') @patch('beets.plugins.inspect') def test_events_called(self, mock_inspect, mock_find_plugins): - mock_inspect.getargspec.return_value = None + mock_inspect.getargspec.args.return_value = None class DummyPlugin(plugins.BeetsPlugin): def __init__(self):