Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package python-pylsp-rope for 
openSUSE:Factory checked in at 2021-10-05 22:34:00
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-pylsp-rope (Old)
 and      /work/SRC/openSUSE:Factory/.python-pylsp-rope.new.2443 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "python-pylsp-rope"

Tue Oct  5 22:34:00 2021 rev:2 rq:923245 version:0.1.4

Changes:
--------
--- /work/SRC/openSUSE:Factory/python-pylsp-rope/python-pylsp-rope.changes      
2021-10-04 18:42:11.718274902 +0200
+++ 
/work/SRC/openSUSE:Factory/.python-pylsp-rope.new.2443/python-pylsp-rope.changes
    2021-10-05 22:34:30.358937560 +0200
@@ -1,0 +2,7 @@
+Tue Oct  5 13:38:59 UTC 2021 - Matej Cepl <mc...@suse.com>
+
+- Update to 0.1.4:
+  - Add method to method object refactoring
+  - Supress all exceptions when determining codeActions
+
+-------------------------------------------------------------------

Old:
----
  pylsp-rope-0.1.3.tar.gz

New:
----
  pylsp-rope-0.1.4.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ python-pylsp-rope.spec ++++++
--- /var/tmp/diff_new_pack.dGFGcE/_old  2021-10-05 22:34:31.094938841 +0200
+++ /var/tmp/diff_new_pack.dGFGcE/_new  2021-10-05 22:34:31.098938848 +0200
@@ -19,7 +19,7 @@
 %{?!python_module:%define python_module() python-%{**} python3-%{**}}
 %define skip_python2 1
 Name:           python-pylsp-rope
-Version:        0.1.3
+Version:        0.1.4
 Release:        0
 Summary:        Extended refactoring capabilities for Python LSP Server using 
Rope
 License:        MIT

++++++ pylsp-rope-0.1.3.tar.gz -> pylsp-rope-0.1.4.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pylsp-rope-0.1.3/MANIFEST.in 
new/pylsp-rope-0.1.4/MANIFEST.in
--- old/pylsp-rope-0.1.3/MANIFEST.in    1970-01-01 01:00:00.000000000 +0100
+++ new/pylsp-rope-0.1.4/MANIFEST.in    2021-10-05 05:14:40.000000000 +0200
@@ -0,0 +1 @@
+recursive-include test/fixtures *.py
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pylsp-rope-0.1.3/PKG-INFO 
new/pylsp-rope-0.1.4/PKG-INFO
--- old/pylsp-rope-0.1.3/PKG-INFO       2021-10-04 09:44:50.108917200 +0200
+++ new/pylsp-rope-0.1.4/PKG-INFO       2021-10-05 05:14:48.619781300 +0200
@@ -1,6 +1,6 @@
 Metadata-Version: 2.1
 Name: pylsp-rope
-Version: 0.1.3
+Version: 0.1.4
 Summary: Extended refactoring capabilities for Python LSP Server using Rope.
 Home-page: https://github.com/python-rope/pylsp-rope
 Author: Lie Ryan
@@ -58,21 +58,29 @@
 - extract method (codeAction)
 - extract variable (codeAction)
 - inline method/variable/parameter (codeAction)
+- method to method object (codeAction)
 - more to come...
 
+Refer to [Rope 
documentation](https://github.com/python-rope/rope/blob/master/docs/overview.rst)
+for more details on how these refactoring works.
+
 ## Usage
 
 ### Extract method
 
-This refactoring works when selecting a block of code.
+This refactoring works by triggering a CodeAction when selecting a block of 
code.
 
 ### Extract variable
 
-This refactoring works when selecting a Python expression.
+This refactoring works by triggering a CodeAction when selecting a Python 
expression.
 
 ### Inline
 
-This refactoring works when the cursor is on a resolvable Python identifier.
+This refactoring works by triggering a CodeAction when the cursor is on a 
resolvable Python identifier.
+
+### Method to method object
+
+This refactoring works when the cursor is on a function definition.
 
 ## Caveat
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pylsp-rope-0.1.3/README.md 
new/pylsp-rope-0.1.4/README.md
--- old/pylsp-rope-0.1.3/README.md      2021-10-03 09:36:49.000000000 +0200
+++ new/pylsp-rope-0.1.4/README.md      2021-10-05 03:45:00.000000000 +0200
@@ -36,21 +36,29 @@
 - extract method (codeAction)
 - extract variable (codeAction)
 - inline method/variable/parameter (codeAction)
+- method to method object (codeAction)
 - more to come...
 
+Refer to [Rope 
documentation](https://github.com/python-rope/rope/blob/master/docs/overview.rst)
+for more details on how these refactoring works.
+
 ## Usage
 
 ### Extract method
 
-This refactoring works when selecting a block of code.
+This refactoring works by triggering a CodeAction when selecting a block of 
code.
 
 ### Extract variable
 
-This refactoring works when selecting a Python expression.
+This refactoring works by triggering a CodeAction when selecting a Python 
expression.
 
 ### Inline
 
-This refactoring works when the cursor is on a resolvable Python identifier.
+This refactoring works by triggering a CodeAction when the cursor is on a 
resolvable Python identifier.
+
+### Method to method object
+
+This refactoring works when the cursor is on a function definition.
 
 ## Caveat
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pylsp-rope-0.1.3/pylsp_rope/commands.py 
new/pylsp-rope-0.1.4/pylsp_rope/commands.py
--- old/pylsp-rope-0.1.3/pylsp_rope/commands.py 2021-10-03 07:13:06.000000000 
+0200
+++ new/pylsp-rope-0.1.4/pylsp_rope/commands.py 2021-10-05 03:38:45.000000000 
+0200
@@ -1,3 +1,4 @@
 COMMAND_REFACTOR_EXTRACT_METHOD = "pylsp_rope.refactor.extract.method"
 COMMAND_REFACTOR_EXTRACT_VARIABLE = "pylsp_rope.refactor.extract.variable"
 COMMAND_REFACTOR_INLINE = "pylsp_rope.refactor.inline"
+COMMAND_REFACTOR_METHOD_TO_METHOD_OBJECT = 
"pylsp_rope.refactor.method_to_method_object"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pylsp-rope-0.1.3/pylsp_rope/plugin.py 
new/pylsp-rope-0.1.4/pylsp_rope/plugin.py
--- old/pylsp-rope-0.1.3/pylsp_rope/plugin.py   2021-10-04 08:39:11.000000000 
+0200
+++ new/pylsp-rope-0.1.4/pylsp_rope/plugin.py   2021-10-05 05:02:12.000000000 
+0200
@@ -3,7 +3,7 @@
 
 import rope.base.exceptions
 from pylsp import hookimpl
-from rope.refactor import extract, inline
+from rope.refactor import extract, inline, method_object
 
 from pylsp_rope import commands
 from pylsp_rope.project import (
@@ -56,133 +56,170 @@
 def pylsp_code_actions(config, workspace, document, range, context):
     logger.info("textDocument/codeAction: %s %s %s", document, range, context)
 
-    current_document, resource = get_resource(workspace, document.uri)
-    range_selection = range["start"] != range["end"]
-    position = range["start"]
-    start_offset = current_document.offset_at_position(range["start"])
-    end_offset = current_document.offset_at_position(range["end"])
-    selected_text = document.source[start_offset:end_offset]
+    class info:
+        current_document, resource = get_resource(workspace, document.uri)
+        position = range["start"]
+        start_offset = current_document.offset_at_position(range["start"])
+        end_offset = current_document.offset_at_position(range["end"])
+        selected_text = document.source[start_offset:end_offset]
+
+    commands = {
+        "Extract method": CommandRefactorExtractMethod(
+            workspace,
+            document_uri=document.uri,
+            range=range,
+        ),
+        "Extract variable": CommandRefactorExtractVariable(
+            workspace,
+            document_uri=document.uri,
+            range=range,
+        ),
+        "Inline method/variable": CommandRefactorInline(
+            workspace,
+            document_uri=document.uri,
+            position=info.position,
+        ),
+        "To method object": CommandRefactorMethodToMethodObject(
+            workspace,
+            document_uri=document.uri,
+            position=info.position,
+        ),
+    }
 
-    code_actions = []
+    return [
+        cmd.get_code_action(title=title)
+        for title, cmd in commands.items()
+        if cmd.is_valid(info)
+    ]
 
-    # FIXME: requires rope.refactor.extract._ExceptionalConditionChecker for 
proper checking
-    code_actions.append(
-        {
-            "title": "Extract method",
-            "kind": "refactor.extract",
+
+@hookimpl
+def pylsp_execute_command(config, workspace, command, arguments):
+    logger.info("workspace/executeCommand: %s %s", command, arguments)
+
+    commands = [
+        CommandRefactorExtractMethod,
+        CommandRefactorExtractVariable,
+        CommandRefactorInline,
+        CommandRefactorMethodToMethodObject,
+    ]
+
+    for cmd in commands:
+        if command == cmd.name:
+            cmd(workspace, **arguments[0])()
+
+
+class Command:
+    def __init__(self, workspace, **arguments):
+        self.workspace = workspace
+        self.arguments = arguments
+        self.__dict__.update(**arguments)
+
+    def is_valid(self, info):
+        try:
+            is_valid = self._is_valid(info)
+        except Exception:
+            return False
+        else:
+            return is_valid
+        return False
+
+    def _is_valid(self, info):
+        return True
+
+    def get_code_action(self, title):
+        return {
+            "title": title,
+            "kind": self.kind,
             "command": {
-                "command": commands.COMMAND_REFACTOR_EXTRACT_METHOD,
-                "arguments": [
-                    {
-                        "document_uri": document.uri,
-                        "range": range,
-                    }
-                ],
+                "command": self.name,
+                "arguments": [self.arguments],
             },
         }
-    )
+
+
+class CommandRefactorExtractMethod(Command):
+    name = commands.COMMAND_REFACTOR_EXTRACT_METHOD
+    kind = "refactor.extract"
 
     # FIXME: requires rope.refactor.extract._ExceptionalConditionChecker for 
proper checking
-    try:
-        ast.parse(selected_text, mode="eval")
-    except SyntaxError:
-        pass
-    else:
-        code_actions.append(
-            {
-                "title": "Extract variable",
-                "kind": "refactor.extract",
-                "command": {
-                    "command": commands.COMMAND_REFACTOR_EXTRACT_VARIABLE,
-                    "arguments": [
-                        {
-                            "document_uri": document.uri,
-                            "range": range,
-                        }
-                    ],
-                },
-            },
+    # def _is_valid(self, info):
+    #     ...
+
+    def __call__(self):
+        current_document, resource = get_resource(self.workspace, 
self.document_uri)
+
+        refactoring = extract.ExtractMethod(
+            project=get_project(self.workspace),
+            resource=resource,
+            
start_offset=current_document.offset_at_position(self.range["start"]),
+            end_offset=current_document.offset_at_position(self.range["end"]),
+        )
+        rope_changeset = refactoring.get_changes(
+            extracted_name="extracted_method",
         )
+        apply_rope_changeset(self.workspace, rope_changeset)
 
-    try:
-        can_inline = inline.create_inline(
-            project=get_project(workspace),
+
+class CommandRefactorExtractVariable(Command):
+    name = commands.COMMAND_REFACTOR_EXTRACT_VARIABLE
+    kind = "refactor.extract"
+
+    def _is_valid(self, info):
+        # FIXME: requires rope.refactor.extract._ExceptionalConditionChecker 
for proper checking
+        ast.parse(info.selected_text, mode="eval")
+        return True
+
+    def __call__(self):
+        current_document, resource = get_resource(self.workspace, 
self.document_uri)
+
+        refactoring = extract.ExtractVariable(
+            project=get_project(self.workspace),
             resource=resource,
-            offset=current_document.offset_at_position(position),
+            
start_offset=current_document.offset_at_position(self.range["start"]),
+            end_offset=current_document.offset_at_position(self.range["end"]),
         )
-    except rope.base.exceptions.RefactoringError as e:
-        pass
-    else:
-        code_actions.append(
-            {
-                "title": "Inline method/variable",
-                "kind": "refactor.inline",
-                "command": {
-                    "command": commands.COMMAND_REFACTOR_INLINE,
-                    "arguments": [
-                        {
-                            "document_uri": document.uri,
-                            "position": range["start"],
-                        }
-                    ],
-                },
-            },
+        rope_changeset = refactoring.get_changes(
+            extracted_name="extracted_variable",
         )
+        apply_rope_changeset(self.workspace, rope_changeset)
 
-    return code_actions
 
+class CommandRefactorInline(Command):
+    name = commands.COMMAND_REFACTOR_INLINE
+    kind = "refactor.inline"
+
+    def _is_valid(self, info):
+        inline.create_inline(
+            project=get_project(self.workspace),
+            resource=info.resource,
+            offset=info.current_document.offset_at_position(info.position),
+        )
+        return True
 
-@hookimpl
-def pylsp_execute_command(config, workspace, command, arguments):
-    logger.info("workspace/executeCommand: %s %s", command, arguments)
+    def __call__(self):
+        current_document, resource = get_resource(self.workspace, 
self.document_uri)
 
-    if command == commands.COMMAND_REFACTOR_EXTRACT_METHOD:
-        refactor_extract_method(workspace, **arguments[0])
+        refactoring = inline.create_inline(
+            project=get_project(self.workspace),
+            resource=resource,
+            offset=current_document.offset_at_position(self.position),
+        )
+        rope_changeset = refactoring.get_changes()
+        apply_rope_changeset(self.workspace, rope_changeset)
 
-    elif command == commands.COMMAND_REFACTOR_EXTRACT_VARIABLE:
-        refactor_extract_variable(workspace, **arguments[0])
 
-    elif command == commands.COMMAND_REFACTOR_INLINE:
-        refactor_inline(workspace, **arguments[0])
+class CommandRefactorMethodToMethodObject(Command):
+    name = commands.COMMAND_REFACTOR_METHOD_TO_METHOD_OBJECT
+    kind = "refactor"
 
+    def __call__(self):
+        current_document, resource = get_resource(self.workspace, 
self.document_uri)
 
-def refactor_extract_method(workspace, document_uri, range):
-    current_document, resource = get_resource(workspace, document_uri)
-
-    refactoring = extract.ExtractMethod(
-        project=get_project(workspace),
-        resource=resource,
-        start_offset=current_document.offset_at_position(range["start"]),
-        end_offset=current_document.offset_at_position(range["end"]),
-    )
-    rope_changeset = refactoring.get_changes(
-        extracted_name="extracted_method",
-    )
-    apply_rope_changeset(workspace, rope_changeset)
-
-
-def refactor_extract_variable(workspace, document_uri, range):
-    current_document, resource = get_resource(workspace, document_uri)
-
-    refactoring = extract.ExtractVariable(
-        project=get_project(workspace),
-        resource=resource,
-        start_offset=current_document.offset_at_position(range["start"]),
-        end_offset=current_document.offset_at_position(range["end"]),
-    )
-    rope_changeset = refactoring.get_changes(
-        extracted_name="extracted_variable",
-    )
-    apply_rope_changeset(workspace, rope_changeset)
-
-
-def refactor_inline(workspace, document_uri, position):
-    current_document, resource = get_resource(workspace, document_uri)
-
-    refactoring = inline.create_inline(
-        project=get_project(workspace),
-        resource=resource,
-        offset=current_document.offset_at_position(position),
-    )
-    rope_changeset = refactoring.get_changes()
-    apply_rope_changeset(workspace, rope_changeset)
+        refactoring = method_object.MethodObject(
+            project=get_project(self.workspace),
+            resource=resource,
+            offset=current_document.offset_at_position(self.position),
+        )
+        rope_changeset = refactoring.get_changes(classname="NewMethodObject")
+        apply_rope_changeset(self.workspace, rope_changeset)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pylsp-rope-0.1.3/pylsp_rope.egg-info/PKG-INFO 
new/pylsp-rope-0.1.4/pylsp_rope.egg-info/PKG-INFO
--- old/pylsp-rope-0.1.3/pylsp_rope.egg-info/PKG-INFO   2021-10-04 
09:44:49.000000000 +0200
+++ new/pylsp-rope-0.1.4/pylsp_rope.egg-info/PKG-INFO   2021-10-05 
05:14:48.000000000 +0200
@@ -1,6 +1,6 @@
 Metadata-Version: 2.1
 Name: pylsp-rope
-Version: 0.1.3
+Version: 0.1.4
 Summary: Extended refactoring capabilities for Python LSP Server using Rope.
 Home-page: https://github.com/python-rope/pylsp-rope
 Author: Lie Ryan
@@ -58,21 +58,29 @@
 - extract method (codeAction)
 - extract variable (codeAction)
 - inline method/variable/parameter (codeAction)
+- method to method object (codeAction)
 - more to come...
 
+Refer to [Rope 
documentation](https://github.com/python-rope/rope/blob/master/docs/overview.rst)
+for more details on how these refactoring works.
+
 ## Usage
 
 ### Extract method
 
-This refactoring works when selecting a block of code.
+This refactoring works by triggering a CodeAction when selecting a block of 
code.
 
 ### Extract variable
 
-This refactoring works when selecting a Python expression.
+This refactoring works by triggering a CodeAction when selecting a Python 
expression.
 
 ### Inline
 
-This refactoring works when the cursor is on a resolvable Python identifier.
+This refactoring works by triggering a CodeAction when the cursor is on a 
resolvable Python identifier.
+
+### Method to method object
+
+This refactoring works when the cursor is on a function definition.
 
 ## Caveat
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pylsp-rope-0.1.3/pylsp_rope.egg-info/SOURCES.txt 
new/pylsp-rope-0.1.4/pylsp_rope.egg-info/SOURCES.txt
--- old/pylsp-rope-0.1.3/pylsp_rope.egg-info/SOURCES.txt        2021-10-04 
09:44:50.000000000 +0200
+++ new/pylsp-rope-0.1.4/pylsp_rope.egg-info/SOURCES.txt        2021-10-05 
05:14:48.000000000 +0200
@@ -1,5 +1,6 @@
 AUTHORS.txt
 LICENSE
+MANIFEST.in
 README.md
 pyproject.toml
 setup.cfg
@@ -23,9 +24,12 @@
 test/test_extract.py
 test/test_inline.py
 test/test_lsp_diff.py
+test/test_method_to_method_object.py
 test/test_project.py
+test/fixtures/function.py
 test/fixtures/many_changes.py
 test/fixtures/many_changes_inlined.py
+test/fixtures/method_object.py
 test/fixtures/simple.py
 test/fixtures/simple_extract_method.py
 test/fixtures/simple_extract_variable.py
\ No newline at end of file
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pylsp-rope-0.1.3/setup.cfg 
new/pylsp-rope-0.1.4/setup.cfg
--- old/pylsp-rope-0.1.3/setup.cfg      2021-10-04 09:44:50.108917200 +0200
+++ new/pylsp-rope-0.1.4/setup.cfg      2021-10-05 05:14:48.619781300 +0200
@@ -1,6 +1,6 @@
 [metadata]
 name = pylsp-rope
-version = 0.1.3
+version = 0.1.4
 author = Lie Ryan
 author_email = lie.1...@gmail.com
 url = https://github.com/python-rope/pylsp-rope
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pylsp-rope-0.1.3/test/fixtures/function.py 
new/pylsp-rope-0.1.4/test/fixtures/function.py
--- old/pylsp-rope-0.1.3/test/fixtures/function.py      1970-01-01 
01:00:00.000000000 +0100
+++ new/pylsp-rope-0.1.4/test/fixtures/function.py      2021-10-05 
05:04:03.000000000 +0200
@@ -0,0 +1,3 @@
+def add(a, b):
+    print(f"{a} + {b} = {a + b}")
+    return a + b
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pylsp-rope-0.1.3/test/fixtures/method_object.py 
new/pylsp-rope-0.1.4/test/fixtures/method_object.py
--- old/pylsp-rope-0.1.3/test/fixtures/method_object.py 1970-01-01 
01:00:00.000000000 +0100
+++ new/pylsp-rope-0.1.4/test/fixtures/method_object.py 2021-10-05 
05:04:03.000000000 +0200
@@ -0,0 +1,13 @@
+def add(a, b):
+    return NewMethodObject(a, b)()
+
+
+class NewMethodObject(object):
+
+    def __init__(self, a, b):
+        self.a = a
+        self.b = b
+
+    def __call__(self):
+        print(f"{self.a} + {self.b} = {self.a + self.b}")
+        return self.a + self.b
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/pylsp-rope-0.1.3/test/test_method_to_method_object.py 
new/pylsp-rope-0.1.4/test/test_method_to_method_object.py
--- old/pylsp-rope-0.1.3/test/test_method_to_method_object.py   1970-01-01 
01:00:00.000000000 +0100
+++ new/pylsp-rope-0.1.4/test/test_method_to_method_object.py   2021-10-05 
03:38:45.000000000 +0200
@@ -0,0 +1,56 @@
+from pylsp_rope import commands, plugin
+from pylsp_rope.text import Range
+from test.conftest import create_document
+from test.helpers import (
+    assert_changeset,
+    assert_code_actions_do_not_offer,
+    assert_single_document_edit,
+)
+
+
+def test_method_to_method_object(config, workspace, code_action_context):
+    document = create_document(workspace, "function.py")
+    line = 0
+    pos = document.lines[line].index("def add") + 4
+    selection = Range((line, pos), (line, pos))
+
+    response = plugin.pylsp_code_actions(
+        config=config,
+        workspace=workspace,
+        document=document,
+        range=selection,
+        context=code_action_context,
+    )
+
+    expected = {
+        "title": "To method object",
+        "kind": "refactor",
+        "command": {
+            "command": commands.COMMAND_REFACTOR_METHOD_TO_METHOD_OBJECT,
+            "arguments": [
+                {
+                    "document_uri": document.uri,
+                    "position": selection["start"],
+                }
+            ],
+        },
+    }
+
+    assert expected in response
+
+    command = expected["command"]["command"]
+    arguments = expected["command"]["arguments"]
+
+    response = plugin.pylsp_execute_command(
+        config=config,
+        workspace=workspace,
+        command=command,
+        arguments=arguments,
+    )
+
+    edit_request = workspace._endpoint.request.call_args
+
+    document_changeset = assert_single_document_edit(edit_request, document)
+    new_text = assert_changeset(document_changeset, target="method_object.py")
+    assert "class NewMethodObject(object)" in new_text
+    assert "NewMethodObject(a, b)()" in new_text

Reply via email to