MCPcopy Index your code
hub / github.com/python/cpython / _prefer_valid

Method _prefer_valid

Lib/importlib/metadata/__init__.py:490–502  ·  view source on GitHub ↗

Prefer (move to the front) distributions that have metadata. Ref python/importlib_resources#489.

(dists: Iterable[Distribution])

Source from the content-addressed store, hash-verified

488
489 @staticmethod
490 def _prefer_valid(dists: Iterable[Distribution]) -> Iterable[Distribution]:
491 """
492 Prefer (move to the front) distributions that have metadata.
493
494 Ref python/importlib_resources#489.
495 """
496
497 has_metadata = ExceptionTrap(MetadataNotFound).passes(
498 operator.attrgetter('metadata')
499 )
500
501 buckets = bucket(dists, has_metadata)
502 return itertools.chain(buckets[True], buckets[False])
503
504 @staticmethod
505 def at(path: str | os.PathLike[str]) -> Distribution:

Callers 1

from_nameMethod · 0.80

Calls 4

ExceptionTrapClass · 0.85
bucketClass · 0.85
passesMethod · 0.80
chainMethod · 0.80

Tested by

no test coverage detected