FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix autoimport raising AttributeError in some cases by douo · Pull Request #309 · python-lsp/python-lsp-server · GitHub

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

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 3 additions & 1 deletion pylsp/plugins/rope_autoimport.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ def pylsp_settings() -> Dict[str, Dict[str, Dict[str, Any]]]:
return {"plugins": {"rope_autoimport": {"enabled": False, "memory": False}}}


def _should_insert(expr: tree.BaseNode, word_node: tree.Leaf) -> bool:
def _should_insert(expr: tree.BaseNode, word_node: tree.Leaf) -> bool: # pylint: disable=too-many-return-statements
"""
Check if we should insert the word_node on the given expr.

Works for both correct and incorrect code. This is because the
user is often working on the code as they write it.
"""
if not word_node:
return False
if len(expr.children) == 0:
return True
first_child = expr.children[0]
Expand Down
5 changes: 5 additions & 0 deletions test/plugins/test_autoimport.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ def test_autoimport_class(completions):
assert len(completions) == 0


@pytest.mark.parametrize("completions", [("""\n""", 0)], indirect=True)
def test_autoimport_empty_line(completions):
assert len(completions) == 0
Comment thread
douo marked this conversation as resolved.


@pytest.mark.parametrize("completions", [("""class Test(NamedTupl):""", 20)],
indirect=True)
def test_autoimport_class_complete(completions):
Expand Down

Back | FazBrowse Home | New Git URL