Remove beets.util.inspect wrapper

This commit is contained in:
Carl Suster 2019-04-02 10:22:47 +11:00
parent 36c85a8aeb
commit 4be2e1b5e6
4 changed files with 16 additions and 32 deletions

View file

@ -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

View file

@ -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)

View file

@ -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:

View file

@ -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):