|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import logging |
4 | | -import sys |
5 | 4 |
|
| 5 | +from collections.abc import Callable |
| 6 | +from collections.abc import Iterator |
6 | 7 | from typing import TYPE_CHECKING |
7 | 8 | from typing import Any |
8 | | -from typing import Callable |
9 | | -from typing import Iterator |
10 | 9 | from typing import cast |
11 | 10 |
|
12 | 11 | __all__ = [ |
|
24 | 23 | log = logging.getLogger(__name__) |
25 | 24 |
|
26 | 25 |
|
27 | | -if sys.version_info[:2] < (3, 10): |
| 26 | +def entry_points(*, group: str, name: str | None = None) -> im.EntryPoints: |
| 27 | + """Get entry points for a specific group (and optionally name). |
28 | 28 |
|
29 | | - def entry_points(*, group: str, name: str | None = None) -> list[im.EntryPoint]: |
30 | | - # Python 3.9: entry_points() returns dict, need to handle filtering manually |
31 | | - |
32 | | - eps = im.entry_points() # Returns dict |
33 | | - |
34 | | - group_eps = eps.get(group, []) |
35 | | - if name is not None: |
36 | | - return [ep for ep in group_eps if ep.name == name] |
37 | | - return group_eps |
38 | | -else: |
39 | | - |
40 | | - def entry_points(*, group: str, name: str | None = None) -> im.EntryPoints: |
41 | | - kw = {"group": group} |
42 | | - if name is not None: |
43 | | - kw["name"] = name |
44 | | - return im.entry_points(**kw) |
| 29 | + In Python 3.10+, entry_points() with group= returns EntryPoints directly. |
| 30 | + """ |
| 31 | + if name is not None: |
| 32 | + return im.entry_points(group=group, name=name) |
| 33 | + else: |
| 34 | + return im.entry_points(group=group) |
45 | 35 |
|
46 | 36 |
|
47 | 37 | def version_from_entrypoint( |
|
0 commit comments