Skip to content

Commit

Permalink
Merge pull request #648 from bagel897/autoimport-fix-bug
Browse files Browse the repository at this point in the history
Remove __init__ from import statement when using sqlite autoimport
  • Loading branch information
lieryan committed Jan 16, 2023
2 parents 811ac7a + 7d447a9 commit 86f1b91
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# **Upcoming release**

- #648 Remove __init__ from import statement when using sqlite autoimport (@bagel897)
- #604 Fix test that sometimes leaves files behind in the current working directory (@lieryan)
- #606 Deprecate compress_objectdb and compress_history (@lieryan)
- #607 Remove importing from legacy files with `.pickle` suffix (@lieryan)
Expand Down
2 changes: 1 addition & 1 deletion rope/contrib/autoimport/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def get_modname_from_path(
for part in rel_path_parts[:-1]:
modname += part
modname += "."
if rel_path_parts[-1] == "__init__":
if rel_path_parts[-1] == "__init__.py":
modname = modname[:-1]
else:
modname = modname + modpath.stem
Expand Down
34 changes: 34 additions & 0 deletions ropetest/contrib/autoimport/autoimporttest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Special cases, easier to express in pytest
from contextlib import closing
from textwrap import dedent

import pytest

from rope.base.project import Project
from rope.base.resources import File, Folder
from rope.contrib.autoimport.sqlite import AutoImport


@pytest.fixture
def autoimport(project: Project):
with closing(AutoImport(project)) as ai:
yield ai


def test_init_py(
autoimport: AutoImport,
project: Project,
pkg1: Folder,
mod1: File,
):
mod1_init = pkg1.get_child("__init__.py")
mod1_init.write(dedent("""\
def foo():
pass
"""))
mod1.write(dedent("""\
foo
"""))
autoimport.generate_cache([mod1_init])
results = autoimport.search("foo", True)
assert [("from pkg1 import foo", "foo")] == results

0 comments on commit 86f1b91

Please sign in to comment.