mirror of
https://github.com/beetbox/beets.git
synced 2025-12-27 02:52:33 +01:00
Fix #2826: introduce beets.util.inspect wrapper
This commit is contained in:
parent
3eb5907da8
commit
520befb30a
2 changed files with 51 additions and 5 deletions
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
from __future__ import division, absolute_import, print_function
|
||||
|
||||
import inspect
|
||||
import traceback
|
||||
import re
|
||||
from collections import defaultdict
|
||||
|
|
@ -27,6 +26,7 @@ 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,10 +127,7 @@ class BeetsPlugin(object):
|
|||
value after the function returns). Also determines which params may not
|
||||
be sent for backwards-compatibility.
|
||||
"""
|
||||
if six.PY2:
|
||||
argspec = inspect.getargspec(func)
|
||||
else:
|
||||
argspec = inspect.getfullargspec(func)
|
||||
argspec = inspect.getargspec(func)
|
||||
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
|
|
|
|||
49
beets/util/inspect.py
Normal file
49
beets/util/inspect.py
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
# -*- 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 absolute_import
|
||||
|
||||
import inspect
|
||||
from collections import namedtuple
|
||||
|
||||
from six import PY2
|
||||
|
||||
|
||||
def getargspec(func):
|
||||
if PY2:
|
||||
return inspect.getargspec(func)
|
||||
|
||||
ArgSpec = namedtuple('ArgSpec', 'args varargs keywords defaults')
|
||||
|
||||
sig = inspect.signature(func)
|
||||
args = [
|
||||
p.name for p in sig.parameters.values()
|
||||
if p.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD
|
||||
]
|
||||
varargs = [
|
||||
p.name for p in sig.parameters.values()
|
||||
if p.kind == inspect.Parameter.VAR_POSITIONAL
|
||||
]
|
||||
varargs = varargs[0] if varargs else None
|
||||
varkw = [
|
||||
p.name for p in sig.parameters.values()
|
||||
if p.kind == inspect.Parameter.VAR_KEYWORD
|
||||
]
|
||||
varkw = varkw[0] if varkw else None
|
||||
defaults = tuple(p.default for p in sig.parameters.values()
|
||||
if p.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD
|
||||
and p.default is not p.empty) or None
|
||||
|
||||
return ArgSpec(args, varargs, varkw, defaults)
|
||||
Loading…
Reference in a new issue