From eb19c647519c754dd93b42a0c421101af73cf7a4 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 24 Jun 2022 21:15:31 -0400 Subject: [PATCH] In Distribution.from_name, require a non-empty string. Fixes python/cpython#93259. --- importlib_metadata/__init__.py | 5 ++++- tests/test_main.py | 2 -- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index 29ce1175..bb1105b6 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -548,7 +548,7 @@ def locate_file(self, path): """ @classmethod - def from_name(cls, name): + def from_name(cls, name: str): """Return the Distribution for the given package name. :param name: The name of the distribution package to search for. @@ -556,7 +556,10 @@ def from_name(cls, name): package, if found. :raises PackageNotFoundError: When the named package's distribution metadata cannot be found. + :raises ValueError: When an invalid value is supplied for name. """ + if not name: + raise ValueError("A distribution name is required.") for resolver in cls._discover_resolvers(): dists = resolver(DistributionFinder.Context(name=name)) dist = next(iter(dists), None) diff --git a/tests/test_main.py b/tests/test_main.py index 041220f1..921f5d9c 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,7 +1,6 @@ import re import json import pickle -import pytest import unittest import warnings import importlib @@ -51,7 +50,6 @@ def test_new_style_classes(self): self.assertIsInstance(Distribution, type) self.assertIsInstance(MetadataPathFinder, type) - @pytest.mark.xfail(reason="Not implemented") @fixtures.parameterize( dict(name=None), dict(name=''),