Skip to content

Commit

Permalink
Harden get_module_part() against "." (#2202) (#2203)
Browse files Browse the repository at this point in the history
(cherry picked from commit bd78ab0)

Co-authored-by: Jacob Walls <[email protected]>
  • Loading branch information
github-actions[bot] and jacobtylerwalls authored Jun 10, 2023
1 parent bbf9ce4 commit 3f6276d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ Release date: TBA



What's New in astroid 2.15.6?
=============================
Release date: 2023-05-14

* Harden ``get_module_part()`` against ``"."``.

Closes pylint-dev/pylint#8749


What's New in astroid 2.15.5?
=============================
Release date: 2023-05-14
Expand Down
3 changes: 2 additions & 1 deletion astroid/modutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ def get_module_part(dotted_name: str, context_file: str | None = None) -> str:
), "explicit relative import, but no context_file?"
path = [] # prevent resolving the import non-relatively
starti = 1
while parts[starti] == "": # for all further dots: change context
# for all further dots: change context
while starti < len(parts) and parts[starti] == "":
starti += 1
assert (
context_file is not None
Expand Down
3 changes: 3 additions & 0 deletions tests/test_modutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ def test_get_module_part_exception(self) -> None:
ImportError, modutils.get_module_part, "unknown.module", modutils.__file__
)

def test_get_module_part_only_dot(self) -> None:
self.assertEqual(modutils.get_module_part(".", modutils.__file__), ".")


class ModPathFromFileTest(unittest.TestCase):
"""Given an absolute file path return the python module's path as a list."""
Expand Down

0 comments on commit 3f6276d

Please sign in to comment.