Skip to content

Commit 469dc2a

Browse files
committed
Raise ValueError on invalid parent
Signed-off-by: Filipe Laíns <lains@riseup.net>
1 parent 282bef7 commit 469dc2a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

Doc/library/importlib.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ ABC hierarchy::
283283

284284
Returns an iterable of possible specs.
285285

286+
Raises :exc:`ValueError` if *parent* is not a package module.
287+
286288
.. warning::
287289
This method can potentially yield a very large number of objects, and
288290
it may carry out IO operations when computing these values.
@@ -335,6 +337,8 @@ ABC hierarchy::
335337

336338
Returns an iterable of possible specs.
337339

340+
Raises :exc:`ValueError` if *parent* is not a package module.
341+
338342
.. warning::
339343
This method can potentially yield a very large number of objects, and
340344
it may carry out IO operations when computing these values.

Lib/importlib/_bootstrap_external.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,9 @@ def _find_children(self):
15121512
break
15131513

15141514
def discover(self, parent=None):
1515+
if parent and parent.submodule_search_locations is None:
1516+
raise ValueError(f'{parent} is not a package module')
1517+
15151518
module_prefix = f'{parent.name}.' if parent else ''
15161519
for child_name in self._find_children():
15171520
if spec := self.find_spec(module_prefix + child_name):

0 commit comments

Comments
 (0)