Skip to content

Commit

Permalink
In Distribution.from_name, require a non-empty string. Fixes python/c…
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jun 25, 2022
1 parent a4ae953 commit eb19c64
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 4 additions & 1 deletion importlib_metadata/__init__.py
Expand Up @@ -548,15 +548,18 @@ 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.
:return: The Distribution instance (or subclass thereof) for the named
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)
Expand Down
2 changes: 0 additions & 2 deletions tests/test_main.py
@@ -1,7 +1,6 @@
import re
import json
import pickle
import pytest
import unittest
import warnings
import importlib
Expand Down Expand Up @@ -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=''),
Expand Down

0 comments on commit eb19c64

Please sign in to comment.