nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: python-lsp/python-lsp-server
Pull request #306 (2022-11-25 02:52:33)

Fix the completion of `include_function_objects`
Fix the completion of `include_function_objects`


Patch:
diff --git a/pylsp/plugins/jedi_completion.py b/pylsp/plugins/jedi_completion.py
index 4c79ebf..4c4bc94 100644
--- a/pylsp/plugins/jedi_completion.py
+++ b/pylsp/plugins/jedi_completion.py
@@ -100,7 +100,8 @@ def pylsp_completions(config, document, position):
             if c.type == 'function':
                 completion_dict = _format_completion(
                     c,
-                    False,
+                    markup_kind=preferred_markup_kind,
+                    include_params=False,
                     resolve=resolve_eagerly,
                     resolve_label_or_snippet=(i < max_to_resolve)
                 )
diff --git a/pylsp/plugins/rope_autoimport.py b/pylsp/plugins/rope_autoimport.py
index f636698..2c0c46e 100644
--- a/pylsp/plugins/rope_autoimport.py
+++ b/pylsp/plugins/rope_autoimport.py
@@ -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]


Test patch:
diff --git a/test/plugins/test_autoimport.py b/test/plugins/test_autoimport.py
index b017b92..a1ddd77 100644
--- a/test/plugins/test_autoimport.py
+++ b/test/plugins/test_autoimport.py
@@ -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
+
+
 @pytest.mark.parametrize("completions", [("""class Test(NamedTupl):""", 20)],
                          indirect=True)
 def test_autoimport_class_complete(completions):
Repository: python-lsp/python-lsp-server
Pull request #447 (2023-10-01 00:39:59)

Fix numpy go-to-definition by taking it off autoimport list for this case
When `numpy` is in the autoimport list, I think go to definition doesn't use the pure static strategy of jedi's `goto` and sees that, e.g., `numpy.ones` has `__module__` set to `numpy` and uses that, while the static strategy correctly sees that `ones` is defined in `numpy.core.numeric`. To fix, in this PR we take everything off the jedi autoimport list before using `goto` for GTD, and we restore it once we're done.

Test plan: added a unit test that passes with this PR and fails without this PR.

smacke: Thanks for the suggestions! Just pushed an update that uses them.

Patch:
diff --git a/pylsp/plugins/definition.py b/pylsp/plugins/definition.py
index ffc1b00..53eda91 100644
--- a/pylsp/plugins/definition.py
+++ b/pylsp/plugins/definition.py
@@ -3,6 +3,9 @@
 from __future__ import annotations
 import logging
 from typing import Any, Dict, List, TYPE_CHECKING
+
+import jedi
+
 from pylsp import hookimpl, uris, _utils
 
 if TYPE_CHECKING:
@@ -43,12 +46,19 @@ def pylsp_definitions(
     settings = config.plugin_settings("jedi_definition")
     code_position = _utils.position_to_jedi_linecolumn(document, position)
     script = document.jedi_script(use_document_path=True)
-    definitions = script.goto(
-        follow_imports=settings.get("follow_imports", True),
-        follow_builtin_imports=settings.get("follow_builtin_imports", True),
-        **code_position,
-    )
-    definitions = [_resolve_definition(d, script, settings) for d in definitions]
+    auto_import_modules = jedi.settings.auto_import_modules
+
+    try:
+        jedi.settings.auto_import_modules = []
+        definitions = script.goto(
+            follow_imports=settings.get("follow_imports", True),
+            follow_builtin_imports=settings.get("follow_builtin_imports", True),
+            **code_position,
+        )
+        definitions = [_resolve_definition(d, script, settings) for d in definitions]
+    finally:
+        jedi.settings.auto_import_modules = auto_import_modules
+
     follow_builtin_defns = settings.get("follow_builtin_definitions", True)
     return [
         {


Test patch:
diff --git a/test/plugins/test_definitions.py b/test/plugins/test_definitions.py
index f0e9ffe..c366e8c 100644
--- a/test/plugins/test_definitions.py
+++ b/test/plugins/test_definitions.py
@@ -36,6 +36,9 @@ my_list = [1, None, alias]
 inception = my_list[2]
 
 inception()
+
+import numpy
+numpy.ones
 """
 
 
@@ -89,6 +92,15 @@ def test_definition_with_multihop_inference_goto(config, workspace):
     )
 
 
+def test_numpy_definition(config, workspace):
+    # Over numpy.ones
+    cursor_pos = {"line": 29, "character": 8}
+
+    doc = Document(DOC_URI, workspace, DOC)
+    defns = pylsp_definitions(config, doc, cursor_pos)
+    assert len(defns) > 0, defns
+
+
 def test_builtin_definition(config, workspace):
     # Over 'i' in dict
     cursor_pos = {"line": 8, "character": 24}
Repository: python-lsp/python-lsp-server
Pull request #457 (2023-10-10 09:54:09)

Fix missing signatures for docstrings in Markdown
Add function signatures to RST style docstrings.

Edited, I was confused before, in plaintext the signatures are there, in RST they're not.

ccordoba12: Thanks @staticf0x for your contribution!

@krassowski, could you take a look at this one? Thanks!
staticf0x: @krassowski thanks, added!

Patch:
diff --git a/pylsp/_utils.py b/pylsp/_utils.py
index 644a00e..9d393b9 100644
--- a/pylsp/_utils.py
+++ b/pylsp/_utils.py
@@ -209,7 +209,6 @@ def format_docstring(
     if markup_kind == "markdown":
         try:
             value = docstring_to_markdown.convert(contents)
-            return {"kind": "markdown", "value": value}
         except docstring_to_markdown.UnknownFormatError:
             # try to escape the Markdown syntax instead:
             value = escape_markdown(contents)


Test patch:
diff --git a/test/test_utils.py b/test/test_utils.py
index 7d01ba0..bc2782d 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -9,6 +9,7 @@ import time
 from unittest import mock
 
 from flaky import flaky
+from docstring_to_markdown import UnknownFormatError
 
 from pylsp import _utils
 from pylsp.python_lsp import PythonLSPServer, start_io_lang_server
@@ -154,3 +155,53 @@ def test_clip_column():
     assert _utils.clip_column(2, ["123\n", "123"], 0) == 2
     assert _utils.clip_column(3, ["123\n", "123"], 0) == 3
     assert _utils.clip_column(4, ["123\n", "123"], 1) == 3
+
+
+@mock.patch("docstring_to_markdown.convert")
+def test_format_docstring_valid_rst_signature(mock_convert):
+    """Test that a valid RST docstring includes the function signature."""
+    docstring = """A function docstring.
+
+    Parameters
+    ----------
+    a : str, something
+    """
+
+    # Mock the return value to avoid depedency on the real thing
+    mock_convert.return_value = """A function docstring.
+
+    #### Parameters
+
+    - `a`: str, something
+    """
+
+    markdown = _utils.format_docstring(
+        docstring,
+        "markdown",
+        ["something(a: str) -> str"],
+    )["value"]
+
+    assert markdown.startswith(
+        _utils.wrap_signature("something(a: str) -> str"),
+    )
+
+
+@mock.patch("docstring_to_markdown.convert", side_effect=UnknownFormatError)
+def test_format_docstring_invalid_rst_signature(_):
+    """Test that an invalid RST docstring includes the function signature."""
+    docstring = """A function docstring.
+
+    Parameters
+    ----------
+    a : str, something
+    """
+
+    markdown = _utils.format_docstring(
+        docstring,
+        "markdown",
+        ["something(a: str) -> str"],
+    )["value"]
+
+    assert markdown.startswith(
+        _utils.wrap_signature("something(a: str) -> str"),
+    )