From 3668b2b2f72929c90a391ed5d82f587382b5a375 Mon Sep 17 00:00:00 2001 From: evidencebp Date: Mon, 11 Nov 2024 19:10:47 +0200 Subject: [PATCH 1/7] plugins\create_package.py broad-exception-caught The function _create_package uses os.mkdir and catch exception. This is too wide since mkdir catches specific exception. That might catch and hide new exception (e.g., in case that more code will be added to the try section). For the mkdir exceptions see: https://docs.python.org/3/library/os.html#os.mkdir --- plugins/create_package.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/create_package.py b/plugins/create_package.py index 61557b27..788284f3 100644 --- a/plugins/create_package.py +++ b/plugins/create_package.py @@ -37,7 +37,9 @@ def _create_package(name): os.mkdir(path) except FileExistsError: logger.error("Path exists already: %r", path) - except Exception: + except FileNotFoundError: + logger.error("Parent path does not exist: %r", path) + except OSError: logger.exception("Unknown error while creating path %r", path) else: return path From a15507c4531a847fb2a25c4b204a671ff82147aa Mon Sep 17 00:00:00 2001 From: evidencebp Date: Mon, 11 Nov 2024 19:28:21 +0200 Subject: [PATCH 2/7] plugins\new_resource_file\__init__.py superfluous-parens Removed unneeded parentheses in return statement --- plugins/new_resource_file/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/new_resource_file/__init__.py b/plugins/new_resource_file/__init__.py index 97cf6445..91307e0e 100644 --- a/plugins/new_resource_file/__init__.py +++ b/plugins/new_resource_file/__init__.py @@ -116,4 +116,4 @@ def _is_package_path(self, file_path): for fp in (real_file_path, file_path): if fp.startswith(pp): leaf = fp[len(pp):].strip(os.sep) - return (os.sep not in leaf) + return os.sep not in leaf From 931b6fde5a7209e723be1541263d6d725ae3781c Mon Sep 17 00:00:00 2001 From: evidencebp Date: Tue, 12 Nov 2024 13:34:46 +0200 Subject: [PATCH 3/7] plugins\command_completions\__init__.py superfluous-parens Removed unneeded parenthesis in python_arg_scope = ("source.python meta.function-call.arguments.python string.quoted") I suspected that the other might intended to create a tuple. To create a single element tuple you need a comma at the end like python_arg_scope = ("source.python meta.function-call.arguments.python string.quoted",) So python_arg_scope was a string anyway Also in line 262, in quite a similar code, there are no parenthesis. --- plugins/command_completions/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/command_completions/__init__.py b/plugins/command_completions/__init__.py index 43c1a93c..b2618376 100644 --- a/plugins/command_completions/__init__.py +++ b/plugins/command_completions/__init__.py @@ -165,7 +165,7 @@ class SublimeTextCommandCompletionPythonListener(sublime_plugin.EventListener): @inhibit_word_completions def on_query_completions(self, view, prefix, locations): loc = locations[0] - python_arg_scope = ("source.python meta.function-call.arguments.python string.quoted") + python_arg_scope = "source.python meta.function-call.arguments.python string.quoted" if not view.score_selector(loc, python_arg_scope) or not is_plugin(view): return None From 470319785b82c1aa92b8e63cbbd63b2e79ce00f8 Mon Sep 17 00:00:00 2001 From: evidencebp Date: Tue, 12 Nov 2024 19:46:10 +0200 Subject: [PATCH 4/7] plugins\syntax_dev\completions.py too-many-return-statements Function match_selector had 7 return statements while pylint recommends to have at most 6. I assigned the return values into the result variable and use a single statement returning in the end of the function. --- plugins/syntax_dev/completions.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/plugins/syntax_dev/completions.py b/plugins/syntax_dev/completions.py index f363ccd1..d55ec800 100644 --- a/plugins/syntax_dev/completions.py +++ b/plugins/syntax_dev/completions.py @@ -232,42 +232,47 @@ def match_selector(selector, offset=0): return all(self.view.match_selector(point + offset, selector) for point in locations) + result = None + # None of our business if not match_selector("- comment - (source.regexp - keyword.other.variable)"): - return None + result = None # Scope name completions based on our scope_data database - if match_selector("meta.expect-scope, meta.scope", -1): - return self._complete_scope(prefix, locations) + elif match_selector("meta.expect-scope, meta.scope", -1): + result = self._complete_scope(prefix, locations) # Auto-completion for include values using the 'contexts' keys and for - if match_selector( + elif match_selector( "meta.expect-context-list-or-content | meta.context-list-or-content", -1, ): - return ((self._complete_keyword(prefix, locations) or []) + result = ((self._complete_keyword(prefix, locations) or []) + self._complete_context(prefix, locations)) # Auto-completion for include values using the 'contexts' keys - if match_selector( + elif match_selector( "meta.expect-context-list | meta.expect-context | meta.include | meta.context-list", -1, ): - return self._complete_context(prefix, locations) or None + result = self._complete_context(prefix, locations) or None # Auto-completion for branch points with 'fail' key - if match_selector( + elif match_selector( "meta.expect-branch-point-reference | meta.branch-point-reference", -1, ): - return self._complete_branch_point() + result = self._complete_branch_point() # Auto-completion for variables in match patterns using 'variables' keys - if match_selector("keyword.other.variable"): - return self._complete_variable() + elif match_selector("keyword.other.variable"): + result = self._complete_variable() - # Standard completions for unmatched regions - return self._complete_keyword(prefix, locations) + else: + # Standard completions for unmatched regions + result = self._complete_keyword(prefix, locations) + + return result def _line_prefix(self, point): _, col = self.view.rowcol(point) From a28ddf7993e4b2799e5c0c1628f84c6e9cbe4da2 Mon Sep 17 00:00:00 2001 From: evidencebp Date: Mon, 18 Nov 2024 13:35:27 +0200 Subject: [PATCH 5/7] plugins\lib\fileconv\dumpers.py unnecessary-pass The methods validate_data and write of DumperProto should be overridden by subclasses (as discussed with FichteFoll). Instead of leaving with just pass changed to raise NotImplementedError to verify that they are not mistakenly used. --- plugins/lib/fileconv/dumpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/lib/fileconv/dumpers.py b/plugins/lib/fileconv/dumpers.py index 4454bafe..e6b19b00 100644 --- a/plugins/lib/fileconv/dumpers.py +++ b/plugins/lib/fileconv/dumpers.py @@ -97,7 +97,7 @@ def validate_data(self, data, *args, **kwargs): (lambda x: x is None, False)) ] """ - pass + raise NotImplementedError def _validate_data(self, data, funcs): """Check for incompatible data recursively. @@ -178,7 +178,7 @@ def dump(self, data, *args, **kwargs): def write(self, data, *args, **kwargs): """To be implemented.""" - pass + raise NotImplementedError class JSONDumper(DumperProto): From 5f972a1a28ab4f7b0fa1d4cc2af752b7583e8a07 Mon Sep 17 00:00:00 2001 From: evidencebp Date: Mon, 18 Nov 2024 13:37:46 +0200 Subject: [PATCH 6/7] plugins\lib\fileconv\loaders.py unnecessary-pass The method parse of LoaderProto should be overridden by subclasses (as discussed with FichteFoll). Instead of leaving with just pass changed to raise NotImplementedError to verify that they are not mistakenly used. --- plugins/lib/fileconv/loaders.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/lib/fileconv/loaders.py b/plugins/lib/fileconv/loaders.py index aa66564a..501ab073 100644 --- a/plugins/lib/fileconv/loaders.py +++ b/plugins/lib/fileconv/loaders.py @@ -295,7 +295,7 @@ def parse(self, *args, **kwargs): """To be implemented. Should return the parsed data from ``self.file_path`` as a Python object. """ - pass + raise NotImplementedError class JSONLoader(LoaderProto): From e4a5d59a3dd84b111dd9ba1d4682ecc11f8f6399 Mon Sep 17 00:00:00 2001 From: FichteFoll Date: Sun, 24 Nov 2024 22:46:26 +0100 Subject: [PATCH 7/7] Address flake 8 lints --- plugins/syntax_dev/completions.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/syntax_dev/completions.py b/plugins/syntax_dev/completions.py index d55ec800..cd79d53b 100644 --- a/plugins/syntax_dev/completions.py +++ b/plugins/syntax_dev/completions.py @@ -247,8 +247,10 @@ def match_selector(selector, offset=0): "meta.expect-context-list-or-content | meta.context-list-or-content", -1, ): - result = ((self._complete_keyword(prefix, locations) or []) - + self._complete_context(prefix, locations)) + result = ( + (self._complete_keyword(prefix, locations) or []) + + self._complete_context(prefix, locations) + ) # Auto-completion for include values using the 'contexts' keys elif match_selector( @@ -271,7 +273,7 @@ def match_selector(selector, offset=0): else: # Standard completions for unmatched regions result = self._complete_keyword(prefix, locations) - + return result def _line_prefix(self, point):