File tree Expand file tree Collapse file tree 5 files changed +39
-1
lines changed
Expand file tree Collapse file tree 5 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 1+ v4.12.0
2+ =======
3+
4+ * py-93259: Now raise ``ValueError `` when ``None `` or an empty
5+ string are passed to ``Distribution.from_name `` (and other
6+ callers).
7+
18v4.11.4
29=======
310
Original file line number Diff line number Diff line change 2020 pattern = r'PEP[- ](?P<pep_number>\d+)' ,
2121 url = 'https://peps.python.org/pep-{pep_number:0>4}/' ,
2222 ),
23+ dict (
24+ pattern = r'(Python #|py-)(?P<python>\d+)' ,
25+ url = 'https://github.com/python/cpython/issues/{python}' ,
26+ ),
2327 ],
2428 )
2529}
Original file line number Diff line number Diff line change @@ -548,15 +548,18 @@ 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.
555555 :return: The Distribution instance (or subclass thereof) for the named
556556 package, if found.
557557 :raises PackageNotFoundError: When the named package's distribution
558558 metadata cannot be found.
559+ :raises ValueError: When an invalid value is supplied for name.
559560 """
561+ if not name :
562+ raise ValueError ("A distribution name is required." )
560563 try :
561564 return next (cls .discover (name = name ))
562565 except StopIteration :
Original file line number Diff line number Diff line change 55import pathlib
66import tempfile
77import textwrap
8+ import functools
89import contextlib
910
1011from .py39compat import FS_NONASCII
@@ -294,3 +295,18 @@ def setUp(self):
294295 # Add self.zip_name to the front of sys.path.
295296 self .resources = contextlib .ExitStack ()
296297 self .addCleanup (self .resources .close )
298+
299+
300+ def parameterize (* args_set ):
301+ """Run test method with a series of parameters."""
302+
303+ def wrapper (func ):
304+ @functools .wraps (func )
305+ def _inner (self ):
306+ for args in args_set :
307+ with self .subTest (** args ):
308+ func (self , ** args )
309+
310+ return _inner
311+
312+ return wrapper
Original file line number Diff line number Diff line change @@ -50,6 +50,14 @@ def test_new_style_classes(self):
5050 self .assertIsInstance (Distribution , type )
5151 self .assertIsInstance (MetadataPathFinder , type )
5252
53+ @fixtures .parameterize (
54+ dict (name = None ),
55+ dict (name = '' ),
56+ )
57+ def test_invalid_inputs_to_from_name (self , name ):
58+ with self .assertRaises (Exception ):
59+ Distribution .from_name (name )
60+
5361
5462class ImportTests (fixtures .DistInfoPkg , unittest .TestCase ):
5563 def test_import_nonexistent_module (self ):
You can’t perform that action at this time.
0 commit comments