nebius/SWE-bench-extra huggingface dataset:
Repository: python-cmd2/cmd2

Issue:
Argparse choices can't be CompletionItems
ArgparseCompleter is converting CompletionItems to normal strings when they appear in a choices list.

Comments:

Patch:
diff --git a/cmd2/argparse_completer.py b/cmd2/argparse_completer.py
index 21007289..ef35eabc 100644
--- a/cmd2/argparse_completer.py
+++ b/cmd2/argparse_completer.py
@@ -641,8 +641,11 @@ class ArgparseCompleter:
                 arg_choices.sort()
                 self._cmd2_app.matches_sorted = True
 
-            # Since choices can be various types, convert them all to strings
-            arg_choices = [str(x) for x in arg_choices]
+            # Since choices can be various types, make sure they are all strings
+            for index, choice in enumerate(arg_choices):
+                # Prevent converting anything that is already a str (i.e. CompletionItem)
+                if not isinstance(choice, str):
+                    arg_choices[index] = str(choice)
         else:
             arg_choices = getattr(arg_state.action, ATTR_CHOICES_CALLABLE, None)
             if arg_choices is None:


Test patch:
diff --git a/tests/test_argparse_completer.py b/tests/test_argparse_completer.py
index 75f24b3e..6002a856 100644
--- a/tests/test_argparse_completer.py
+++ b/tests/test_argparse_completer.py
@@ -107,6 +107,7 @@ class ArgparseCompleterTester(cmd2.Cmd):
     int_choices = [-1, 1, -2, 2, 0, -12]
     static_choices_list = ['static', 'choices', 'stop', 'here']
     choices_from_provider = ['choices', 'provider', 'probably', 'improved']
+    completion_item_choices = [CompletionItem('choice_1', 'A description'), CompletionItem('choice_2', 'Another description')]
 
     def choices_provider(self) -> List[str]:
         """Method that provides choices"""
@@ -150,6 +151,7 @@ class ArgparseCompleterTester(cmd2.Cmd):
         nargs=argparse.ONE_OR_MORE,
     )
     choices_parser.add_argument('-i', '--int', type=int, help='a flag with an int type', choices=int_choices)
+    choices_parser.add_argument('--completion_items', help='choices are CompletionItems', choices=completion_item_choices)
 
     # Positional args for choices command
     choices_parser.add_argument("list_pos", help="a positional populated with a choices list", choices=static_choices_list)
@@ -729,6 +731,23 @@ def test_completion_items(ac_app, num_aliases, show_description):
         assert 'help' in first_result_line
 
 
+def test_completion_item_choices(ac_app):
+    text = ''
+    line = 'choices --completion_items {}'.format(text)
+    endidx = len(line)
+    begidx = endidx - len(text)
+
+    first_match = complete_tester(text, line, begidx, endidx, ac_app)
+    assert first_match is not None
+    assert len(ac_app.completion_matches) == len(ac_app.completion_item_choices)
+    assert len(ac_app.display_matches) == len(ac_app.completion_item_choices)
+
+    # Make sure a completion table was created
+    first_result_line = normalize(ac_app.formatted_completions)[1]
+    assert 'choice_1' in first_result_line
+    assert 'A description' in first_result_line
+
+
 @pytest.mark.parametrize(
     'args, completions',
     [
Repository: python-cmd2/cmd2

Issue:
py command doesn't properly respect locals_in_py=False if it was ever True
Currently the **py** command will have ``self`` accessible forevermore if the ``locals_in_py`` attribute ever gets set to True - changing it back to False will have no effect.

Either setting it to False should make ``self`` no longer accessible within **py** OR ``locals_in_py`` should not be a runtime settable parameter.

Comments:

Patch:
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 03c71a91..e04138fa 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -2982,6 +2982,8 @@ class Cmd(cmd.Cmd):
 
             if self.locals_in_py:
                 self.pystate['self'] = self
+            elif 'self' in self.pystate:
+                del self.pystate['self']
 
             localvars = self.pystate
             from code import InteractiveConsole


Test patch:
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index a382a940..3d57a105 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -216,18 +216,35 @@ def test_base_shell(base_app, monkeypatch):
     assert m.called
 
 def test_base_py(base_app, capsys):
+    # Create a variable and make sure we can see it
     run_cmd(base_app, 'py qqq=3')
     out, err = capsys.readouterr()
     assert out == ''
-
     run_cmd(base_app, 'py print(qqq)')
     out, err = capsys.readouterr()
     assert out.rstrip() == '3'
 
+    # Add a more complex statement
     run_cmd(base_app, 'py print("spaces" + " in this " + "command")')
     out, err = capsys.readouterr()
     assert out.rstrip() == 'spaces in this command'
 
+    # Set locals_in_py to True and make sure we see self
+    out = run_cmd(base_app, 'set locals_in_py True')
+    assert 'now: True' in out
+
+    run_cmd(base_app, 'py print(self)')
+    out, err = capsys.readouterr()
+    assert 'cmd2.cmd2.Cmd object' in out
+
+    # Set locals_in_py to False and make sure we can't see self
+    out = run_cmd(base_app, 'set locals_in_py False')
+    assert 'now: False' in out
+
+    run_cmd(base_app, 'py print(self)')
+    out, err = capsys.readouterr()
+    assert "name 'self' is not defined" in err
+
 
 @pytest.mark.skipif(sys.platform == 'win32',
                     reason="Unit test doesn't work on win32, but feature does")
Repository: python-cmd2/cmd2

Issue:
CommandResult is False for cmd2 built-ins
Since no built-in **cmd2** command fills out `self._last_result`, `CommandResult` is always **False** when running these commands in `pyscript`.

Comments:

Patch:
diff --git a/cmd2/pyscript_bridge.py b/cmd2/pyscript_bridge.py
index 2002ca6d..7c09aab0 100644
--- a/cmd2/pyscript_bridge.py
+++ b/cmd2/pyscript_bridge.py
@@ -33,9 +33,16 @@ class CommandResult(namedtuple_with_defaults('CommandResult', ['stdout', 'stderr
 
     NOTE: Named tuples are immutable.  So the contents are there for access, not for modification.
     """
-    def __bool__(self):
-        """If stderr is None and data is not None the command is considered a success"""
-        return not self.stderr and self.data is not None
+    def __bool__(self) -> bool:
+        """Returns True if the command succeeded, otherwise False"""
+
+        # If data has a __bool__ method, then call it to determine success of command
+        if self.data is not None and callable(getattr(self.data, '__bool__', None)):
+            return bool(self.data)
+
+        # Otherwise check if stderr was filled out
+        else:
+            return not self.stderr
 
 
 def _exec_cmd(cmd2_app, func: Callable, echo: bool) -> CommandResult:


Test patch:
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index a64f21e4..a2bd6197 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -1576,8 +1576,14 @@ class CommandResultApp(cmd2.Cmd):
         self._last_result = cmd2.CommandResult(arg, data=True)
 
     def do_negative(self, arg):
+        self._last_result = cmd2.CommandResult(arg, data=False)
+
+    def do_affirmative_no_data(self, arg):
         self._last_result = cmd2.CommandResult(arg)
 
+    def do_negative_no_data(self, arg):
+        self._last_result = cmd2.CommandResult('', arg)
+
 @pytest.fixture
 def commandresult_app():
     app = CommandResultApp()
@@ -1590,11 +1596,19 @@ def test_commandresult_truthy(commandresult_app):
     assert commandresult_app._last_result
     assert commandresult_app._last_result == cmd2.CommandResult(arg, data=True)
 
+    run_cmd(commandresult_app, 'affirmative_no_data {}'.format(arg))
+    assert commandresult_app._last_result
+    assert commandresult_app._last_result == cmd2.CommandResult(arg)
+
 def test_commandresult_falsy(commandresult_app):
     arg = 'bar'
     run_cmd(commandresult_app, 'negative {}'.format(arg))
     assert not commandresult_app._last_result
-    assert commandresult_app._last_result == cmd2.CommandResult(arg)
+    assert commandresult_app._last_result == cmd2.CommandResult(arg, data=False)
+
+    run_cmd(commandresult_app, 'negative_no_data {}'.format(arg))
+    assert not commandresult_app._last_result
+    assert commandresult_app._last_result == cmd2.CommandResult('', arg)
 
 
 def test_is_text_file_bad_input(base_app):
Repository: python-lsp/python-lsp-server

Issue:
notebookDocumentSync notebookSelector type error
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notebookDocumentSyncOptions

The notebookSelector should be an array type. But now the object is returned.
![image](https://github.com/python-lsp/python-lsp-server/assets/35445052/77c8f038-45ed-4c0c-a9c5-59940a399e8d)


Comments:

Patch:
diff --git a/pylsp/python_lsp.py b/pylsp/python_lsp.py
index 3eeb2f7..e2b541d 100644
--- a/pylsp/python_lsp.py
+++ b/pylsp/python_lsp.py
@@ -295,7 +295,7 @@ class PythonLSPServer(MethodDispatcher):
                 "openClose": True,
             },
             "notebookDocumentSync": {
-                "notebookSelector": {"cells": [{"language": "python"}]}
+                "notebookSelector": [{"cells": [{"language": "python"}]}]
             },
             "workspace": {
                 "workspaceFolders": {"supported": True, "changeNotifications": True}


Test patch:
diff --git a/test/test_notebook_document.py b/test/test_notebook_document.py
index e8e7ac7..6050b58 100644
--- a/test/test_notebook_document.py
+++ b/test/test_notebook_document.py
@@ -33,7 +33,8 @@ def test_initialize(client_server_pair):
         },
     ).result(timeout=CALL_TIMEOUT_IN_SECONDS)
     assert server.workspace is not None
-    assert "notebookDocumentSync" in response["capabilities"].keys()
+    selector = response["capabilities"]["notebookDocumentSync"]["notebookSelector"]
+    assert isinstance(selector, list)
 
 
 @pytest.mark.skipif(IS_WIN, reason="Flaky on Windows")