Skip to content

Commit

Permalink
Merge pull request #483 from Danyal-Faheem/add-types-for-untyped-methods
Browse files Browse the repository at this point in the history
Add typing for load and select
  • Loading branch information
jaraco authored Mar 7, 2024
2 parents 0ae1d24 + 9d4908e commit 26b22b8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from importlib import import_module
from importlib.abc import MetaPathFinder
from itertools import starmap
from typing import Iterable, List, Mapping, Optional, Set, cast
from typing import Any, Iterable, List, Mapping, Match, Optional, Set, cast

__all__ = [
'Distribution',
Expand Down Expand Up @@ -175,12 +175,12 @@ class EntryPoint:
def __init__(self, name: str, value: str, group: str) -> None:
vars(self).update(name=name, value=value, group=group)

def load(self):
def load(self) -> Any:
"""Load the entry point from its definition. If only a module
is indicated by the value, return that module. Otherwise,
return the named object.
"""
match = self.pattern.match(self.value)
match = cast(Match, self.pattern.match(self.value))
module = import_module(match.group('module'))
attrs = filter(None, (match.group('attr') or '').split('.'))
return functools.reduce(getattr, attrs, module)
Expand Down Expand Up @@ -275,7 +275,7 @@ def __repr__(self):
"""
return '%s(%r)' % (self.__class__.__name__, tuple(self))

def select(self, **params):
def select(self, **params) -> EntryPoints:
"""
Select entry points from self that match the
given parameters (typically group and/or name).
Expand Down

0 comments on commit 26b22b8

Please sign in to comment.