|
29 | 29 | from importlib import import_module |
30 | 30 | from importlib.abc import MetaPathFinder |
31 | 31 | from itertools import starmap |
32 | | -from typing import List, Mapping, Optional, Union |
| 32 | +from typing import List, Mapping, Optional, Tuple, Union |
33 | 33 |
|
34 | 34 |
|
35 | 35 | __all__ = [ |
@@ -378,7 +378,8 @@ def select(self, **params): |
378 | 378 | Select entry points from self that match the |
379 | 379 | given parameters (typically group and/or name). |
380 | 380 | """ |
381 | | - return EntryPoints(ep for ep in self if ep.matches(**params)) |
| 381 | + candidates = (_ep_matches(ep, **params) for ep in self) |
| 382 | + return EntryPoints(ep for ep, ep_matches in candidates if ep_matches) |
382 | 383 |
|
383 | 384 | @property |
384 | 385 | def names(self): |
@@ -410,6 +411,15 @@ def _from_text(text): |
410 | 411 | ) |
411 | 412 |
|
412 | 413 |
|
| 414 | +def _ep_matches(ep: EntryPoint, **params) -> Tuple[EntryPoint, bool]: |
| 415 | + """Compatibility layer for EntryPoint objects in Python 3.8/3.9 stdlib.""" |
| 416 | + try: |
| 417 | + return ep, ep.matches(**params) |
| 418 | + except AttributeError: |
| 419 | + _ep = EntryPoint(ep.name, ep.value, ep.group) |
| 420 | + return _ep, _ep.matches(**params) |
| 421 | + |
| 422 | + |
413 | 423 | class Deprecated: |
414 | 424 | """ |
415 | 425 | Compatibility add-in for mapping to indicate that |
@@ -1021,7 +1031,8 @@ def _compat_normalized_name(dist: Distribution) -> Optional[str]: |
1021 | 1031 | that don't provide ``_normalized_name`` |
1022 | 1032 | (as in ``importlib.metadata`` for Python 3.8/3.9). |
1023 | 1033 | """ |
1024 | | - return getattr(dist, '_normalized_name', None) or Prepared.normalize(dist.name) |
| 1034 | + normalized = getattr(dist, '_normalized_name', None) |
| 1035 | + return normalized or Prepared.normalize(getattr(dist, "name", "")) |
1025 | 1036 |
|
1026 | 1037 |
|
1027 | 1038 | _unique = functools.partial( |
|
0 commit comments