Skip to content

Commit b3f5458

Browse files
committed
plugins.handlers: use stdlib for EntryPointPlugin.get_version()
`importlib.metadata` officially starts existing in Python 3.8, and we are removing support for Python 3.7 before Sopel 8's stable release. That means we can use the stdlib approach here to get the version string for an entry-point plugin, and drop another `import importlib_metadata`. I can't wait for Python 3.9's EOL... We can remove `importlib_metadata` completely then.
1 parent bef5229 commit b3f5458

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

sopel/plugins/handlers.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@
5252
import sys
5353
from typing import Optional, TYPE_CHECKING, TypedDict
5454

55-
# TODO: refactor along with usage in sopel.__init__ in py3.8+ world
56-
import importlib_metadata
57-
5855
from sopel import __version__ as release, loader, plugin as plugin_decorators
5956
from . import exceptions
6057

@@ -614,9 +611,13 @@ def get_version(self) -> Optional[str]:
614611
"""
615612
version: Optional[str] = super().get_version()
616613

617-
if version is None and hasattr(self.module, "__package__"):
614+
if (
615+
version is None
616+
and hasattr(self.module, "__package__")
617+
and self.module.__package__ is not None
618+
):
618619
try:
619-
version = importlib_metadata.version(self.module.__package__)
620+
version = importlib.metadata.version(self.module.__package__)
620621
except ValueError:
621622
# package name is probably empty-string; just give up
622623
pass

0 commit comments

Comments
 (0)