--- a/RefactoringRope/RefactoringClient.py Sat Mar 27 09:48:05 2021 +0100 +++ b/RefactoringRope/RefactoringClient.py Sat Apr 24 11:19:08 2021 +0200 @@ -9,11 +9,7 @@ import sys import os - -try: - str = unicode # __IGNORE_WARNING__ __IGNORE_EXCEPTION__ -except NameError: - pass +import contextlib sys.path.insert(0, os.path.dirname(__file__)) @@ -40,7 +36,7 @@ @param projectPath path to the project @type str """ - super(RefactoringClient, self).__init__(host, port) + super().__init__(host, port) self.__methodMapping = { "AbortAction": self.__abortAction, @@ -358,12 +354,9 @@ filename = params["FileName"] oldSource = params["OldSource"] - try: + with contextlib.suppress(Exception): rope.base.libutils.report_change( self.__project, filename, oldSource) - except Exception: # secok - # simply ignore it - pass def __processHistory(self, params): """ @@ -442,10 +435,8 @@ self.__project.history.clear() elif subcommand == "ClearChanges": - try: + with contextlib.suppress(KeyError): del self.__changes["History"] - except KeyError: - pass def __clearChanges(self, params): """ @@ -455,10 +446,8 @@ the server @type dict """ - try: + with contextlib.suppress(KeyError): del self.__changes[params["ChangeGroup"]] - except KeyError: - pass def __applyChanges(self, params): """ @@ -555,10 +544,7 @@ resource = rope.base.libutils.path_to_resource( self.__project, filename) - if isLocal: - resources = [resource] - else: - resources = None + resources = [resource] if isLocal else None self.__progressHandle = ProgressHandle(self, title, True) try: @@ -683,14 +669,14 @@ resource = rope.base.libutils.path_to_resource( self.__project, filename) try: - if kind == "variable": + if kind not in ("variable", "method"): + raise Exception("Invalid extraction kind <{0}>.".format(kind)) + elif kind == "variable": extractor = rope.refactor.extract.ExtractVariable( self.__project, resource, startOffset, endOffset) elif kind == "method": extractor = rope.refactor.extract.ExtractMethod( self.__project, resource, startOffset, endOffset) - else: - raise Exception("Invalid extraction kind <{0}>.".format(kind)) changes = extractor.get_changes( newName, similar=similar, global_=global_) except Exception as err: @@ -770,15 +756,12 @@ try: inliner = rope.refactor.inline.create_inline( self.__project, resource, offset) - if kind == "parameter": - opts = { - "in_hierarchy": params["Hierarchy"], - } - else: - opts = { - "remove": params["Remove"], - "only_current": params["OnlyCurrent"], - } + opts = ( + {"in_hierarchy": params["Hierarchy"], } + if kind == "parameter" else + {"remove": params["Remove"], + "only_current": params["OnlyCurrent"], } + ) changes = inliner.get_changes( task_handle=self.__progressHandle, **opts) except Exception as err: @@ -1099,10 +1082,7 @@ self.__changes[changeGroup] = changes # send the change description first - if changes: - description = changes.description - else: - description = "" + description = changes.description if changes else "" self.sendJson("Changes", { "ChangeGroup": changeGroup, "Title": title, @@ -1331,10 +1311,7 @@ self.__changes[changeGroup] = changes # send the change description first - if changes: - description = changes.description - else: - description = "" + description = changes.description if changes else "" self.sendJson("Changes", { "ChangeGroup": changeGroup, "Title": title, @@ -1464,10 +1441,7 @@ self.__changes[changeGroup] = changes # send the change description first - if changes: - description = changes.description - else: - description = "" + description = changes.description if changes else "" self.sendJson("Changes", { "ChangeGroup": changeGroup, "Title": title,