Skip to content

Commit 26b22b8

Browse files
authored
Merge pull request #483 from Danyal-Faheem/add-types-for-untyped-methods
Add typing for load and select
2 parents 0ae1d24 + 9d4908e commit 26b22b8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

importlib_metadata/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from importlib import import_module
3434
from importlib.abc import MetaPathFinder
3535
from itertools import starmap
36-
from typing import Iterable, List, Mapping, Optional, Set, cast
36+
from typing import Any, Iterable, List, Mapping, Match, Optional, Set, cast
3737

3838
__all__ = [
3939
'Distribution',
@@ -175,12 +175,12 @@ class EntryPoint:
175175
def __init__(self, name: str, value: str, group: str) -> None:
176176
vars(self).update(name=name, value=value, group=group)
177177

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

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

0 commit comments

Comments
 (0)