diff --git a/CHANGELOG.md b/CHANGELOG.md index eccb2d228..3b680dc7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/rope/contrib/autoimport/utils.py b/rope/contrib/autoimport/utils.py index 55cc16b71..6d8f9b414 100644 --- a/rope/contrib/autoimport/utils.py +++ b/rope/contrib/autoimport/utils.py @@ -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 diff --git a/ropetest/contrib/autoimport/autoimporttest.py b/ropetest/contrib/autoimport/autoimporttest.py new file mode 100644 index 000000000..7a5a05b6e --- /dev/null +++ b/ropetest/contrib/autoimport/autoimporttest.py @@ -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