Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: relative imports from '' package are not allowed #894

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libcst/helpers/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def get_absolute_module_from_package(
if num_dots == 0:
# This is an absolute import, so the module is correct.
return module_name
if current_package is None:
if current_package is None or current_package == "":
# We don't actually have the current module available, so we can't compute
# the absolute module from relative.
return None
Expand Down
3 changes: 3 additions & 0 deletions libcst/helpers/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ def test_get_absolute_module(
("x/y/z/__init__.py", "from a.b import c", "a.b"),
# Relative import that can't be resolved due to missing module.
(None, "from ..w import c", None),
# Attempted relative import with no known parent package
("__init__.py", "from .y import z", None),
("x.py", "from .y import z", None),
# Relative import that goes past the module level.
("x.py", "from ...y import z", None),
("x/y/z.py", "from ... import c", None),
Expand Down