Skip to content

Commit 3a4a4b7

Browse files
committed
plugins: use importlib and inspect instead __import__ and __dict__
also remove a unnecessary check before adding to a set
1 parent c0f8714 commit 3a4a4b7

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

beets/plugins.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import traceback
2323
from collections import defaultdict
2424
from functools import wraps
25+
from importlib import import_module
2526
from typing import TYPE_CHECKING
2627

2728
import mediafile
@@ -269,10 +270,8 @@ def load_plugins(names=()):
269270
BeetsPlugin subclasses desired.
270271
"""
271272
for name in names:
272-
modname = f"{PLUGIN_NAMESPACE}.{name}"
273-
274273
try:
275-
namespace = __import__(modname, None, None)
274+
mod = import_module(name, package=PLUGIN_NAMESPACE)
276275
except ModuleNotFoundError:
277276
log.warning("** plugin {} not found", name)
278277
continue
@@ -284,13 +283,8 @@ def load_plugins(names=()):
284283
)
285284
continue
286285

287-
for obj in getattr(namespace, name).__dict__.values():
288-
if (
289-
isinstance(obj, type)
290-
and issubclass(obj, BeetsPlugin)
291-
and obj != BeetsPlugin
292-
and obj not in _classes
293-
):
286+
for _name, obj in inspect.getmembers(mod, inspect.isclass):
287+
if issubclass(obj, BeetsPlugin) and obj != BeetsPlugin:
294288
_classes.add(obj)
295289

296290

0 commit comments

Comments
 (0)