Skip to content

Commit d97e389

Browse files
committed
Rely on keyword-only argument for context.
1 parent 3c4fd4e commit d97e389

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

importlib_metadata/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ def __repr__(self) -> str:
336336

337337

338338
class DeprecatedNonAbstract:
339+
# Required until Python 3.14
339340
def __new__(cls, *args, **kwargs):
340341
all_names = {
341342
name for subclass in inspect.getmro(cls) for name in vars(subclass)
@@ -391,16 +392,18 @@ def from_name(cls, name: str) -> "Distribution":
391392
raise PackageNotFoundError(name)
392393

393394
@classmethod
394-
def discover(cls, **kwargs) -> Iterable["Distribution"]:
395+
def discover(
396+
cls, *, context: Optional['DistributionFinder.Context'] = None, **kwargs
397+
) -> Iterable["Distribution"]:
395398
"""Return an iterable of Distribution objects for all packages.
396399
397400
Pass a ``context`` or pass keyword arguments for constructing
398401
a context.
399402
400403
:context: A ``DistributionFinder.Context`` object.
401-
:return: Iterable of Distribution objects for all packages.
404+
:return: Iterable of Distribution objects for packages matching
405+
the context.
402406
"""
403-
context = kwargs.pop('context', None)
404407
if context and kwargs:
405408
raise ValueError("cannot accept context and kwargs")
406409
context = context or DistributionFinder.Context(**kwargs)

0 commit comments

Comments
 (0)