summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2021-03-15 02:20:49 (GMT)
committerGitHub <noreply@github.com>2021-03-15 02:20:49 (GMT)
commit35d5068928ab5485e5f28b60b1e33062bc2c46cc (patch)
treef62e620916b4890d61603cfda7497a7a30bb3025 /Lib/importlib
parent5e29021a5eb10baa9147fd977cab82fa3f652bf0 (diff)
downloadcpython-35d5068928ab5485e5f28b60b1e33062bc2c46cc.zip
cpython-35d5068928ab5485e5f28b60b1e33062bc2c46cc.tar.gz
cpython-35d5068928ab5485e5f28b60b1e33062bc2c46cc.tar.bz2
bpo-43428: Improve documentation for importlib.metadata changes. (GH-24858)
* bpo-43428: Sync with importlib_metadata 3.7.3 (16ac3a95) * Add 'versionadded' for importlib.metadata.packages_distributions * Add section in what's new for Python 3.10 highlighting most salient changes and relevant backport.
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/metadata.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/Lib/importlib/metadata.py b/Lib/importlib/metadata.py
index 8a73185..53c1a14 100644
--- a/Lib/importlib/metadata.py
+++ b/Lib/importlib/metadata.py
@@ -4,7 +4,6 @@ import abc
import csv
import sys
import email
-import inspect
import pathlib
import zipfile
import operator
@@ -12,7 +11,7 @@ import warnings
import functools
import itertools
import posixpath
-import collections.abc
+import collections
from ._itertools import unique_everseen
@@ -33,6 +32,7 @@ __all__ = [
'entry_points',
'files',
'metadata',
+ 'packages_distributions',
'requires',
'version',
]
@@ -158,21 +158,33 @@ class EntryPoints(tuple):
__slots__ = ()
def __getitem__(self, name): # -> EntryPoint:
+ """
+ Get the EntryPoint in self matching name.
+ """
try:
return next(iter(self.select(name=name)))
except StopIteration:
raise KeyError(name)
def select(self, **params):
+ """
+ Select entry points from self that match the
+ given parameters (typically group and/or name).
+ """
return EntryPoints(ep for ep in self if ep.matches(**params))
@property
def names(self):
+ """
+ Return the set of all names of all entry points.
+ """
return set(ep.name for ep in self)
@property
def groups(self):
"""
+ Return the set of all groups of all entry points.
+
For coverage while SelectableGroups is present.
>>> EntryPoints().groups
set()
@@ -185,6 +197,9 @@ class EntryPoints(tuple):
def flake8_bypass(func):
+ # defer inspect import as performance optimization.
+ import inspect
+
is_flake8 = any('flake8' in str(frame.filename) for frame in inspect.stack()[:5])
return func if not is_flake8 else lambda: None
@@ -813,6 +828,7 @@ def packages_distributions() -> Mapping[str, List[str]]:
Return a mapping of top-level packages to their
distributions.
+ >>> import collections.abc
>>> pkgs = packages_distributions()
>>> all(isinstance(dist, collections.abc.Sequence) for dist in pkgs.values())
True