Skip to content

Commit

Permalink
Handle empty modname in ast_from_module_name (#1801)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord committed Sep 23, 2022
1 parent 8559936 commit 6eb73d0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions astroid/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ def ast_from_module_name( # noqa: C901
use_cache: bool = True,
) -> nodes.Module:
"""Given a module name, return the astroid object."""
if modname is None:
raise AstroidBuildingError("No module name given.")
# Sometimes we don't want to use the cache. For example, when we're
# importing a module with the same name as the file that is importing
# we want to fallback on the import system to make sure we get the correct
Expand Down
4 changes: 4 additions & 0 deletions tests/unittest_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ def test_same_name_import_module(self) -> None:
stdlib_math = next(module.body[1].value.args[0].infer())
assert self.manager.astroid_cache["math"] != stdlib_math

def test_raises_exception_for_empty_modname(self) -> None:
with pytest.raises(AstroidBuildingError):
self.manager.ast_from_module_name(None)


class BorgAstroidManagerTC(unittest.TestCase):
def test_borg(self) -> None:
Expand Down

0 comments on commit 6eb73d0

Please sign in to comment.