Skip to content

Commit f9c082a

Browse files
committed
In Distribution.from_name, require a non-empty string. Fixes python/cpython#93259.
1 parent a4ae953 commit f9c082a

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

importlib_metadata/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ def locate_file(self, path):
548548
"""
549549

550550
@classmethod
551-
def from_name(cls, name):
551+
def from_name(cls, name: str):
552552
"""Return the Distribution for the given package name.
553553
554554
:param name: The name of the distribution package to search for.
@@ -557,6 +557,8 @@ def from_name(cls, name):
557557
:raises PackageNotFoundError: When the named package's distribution
558558
metadata cannot be found.
559559
"""
560+
if not name:
561+
raise ValueError("A distribution name is required.")
560562
for resolver in cls._discover_resolvers():
561563
dists = resolver(DistributionFinder.Context(name=name))
562564
dist = next(iter(dists), None)

tests/test_main.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import re
22
import json
33
import pickle
4-
import pytest
54
import unittest
65
import warnings
76
import importlib
@@ -51,7 +50,6 @@ def test_new_style_classes(self):
5150
self.assertIsInstance(Distribution, type)
5251
self.assertIsInstance(MetadataPathFinder, type)
5352

54-
@pytest.mark.xfail(reason="Not implemented")
5553
@fixtures.parameterize(
5654
dict(name=None),
5755
dict(name=''),

0 commit comments

Comments
 (0)