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

Remove __init__ from import statement when using sqlite autoimport #648

Merged
merged 7 commits into from
Jan 16, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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