From d894f794fc108e45d88f2bdca07fe36f9c13d9c3 Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Tue, 5 Nov 2019 09:51:50 +0100 Subject: [PATCH] Add mypy configuration & tweak pylint configuration. (#1128) --- mypy.ini | 12 +++++++ pylintrc | 11 +++++-- pythonx/UltiSnips/snippet/definition/base.py | 2 +- pythonx/UltiSnips/snippet_manager.py | 33 +++++++++----------- 4 files changed, 36 insertions(+), 22 deletions(-) create mode 100644 mypy.ini diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 00000000..3fe42135 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,12 @@ +# Global options: + +[mypy] +python_version = 3.7 +warn_return_any = True +warn_unused_configs = True + +[mypy-vim] +ignore_missing_imports = True + +[mypy-unidecode] +ignore_missing_imports = True diff --git a/pylintrc b/pylintrc index 9d986cf0..c883785a 100644 --- a/pylintrc +++ b/pylintrc @@ -34,7 +34,12 @@ load-plugins= # --disable=W" disable= attribute-defined-outside-init, + bad-continuation, fixme, + import-error, + missing-class-docstring, + missing-function-docstring, + missing-module-docstring, redefined-builtin, too-few-public-methods, too-many-arguments, @@ -44,7 +49,8 @@ disable= too-many-public-methods, too-many-return-statements, too-many-statements, - bad-continuation, + useless-object-inheritance, + [REPORTS] @@ -119,7 +125,7 @@ docstring-min-length=-1 [FORMAT] # Maximum number of characters on a single line. -max-line-length=80 +max-line-length=110 # Regexp for a line that is allowed to be longer than the limit. ignore-long-lines=^\s*(# )??$ @@ -169,6 +175,7 @@ ignore-mixin-members=yes # List of classes names for which member attributes should not be checked # (useful for classes with attributes dynamically set). ignored-classes=SQLObject +ignored-modules=vim # When zope mode is activated, add a predefined set of Zope acquired attributes # to generated-members. diff --git a/pythonx/UltiSnips/snippet/definition/base.py b/pythonx/UltiSnips/snippet/definition/base.py index 2f870602..908c348e 100644 --- a/pythonx/UltiSnips/snippet/definition/base.py +++ b/pythonx/UltiSnips/snippet/definition/base.py @@ -107,7 +107,7 @@ def __init__( self._location = location self._context_code = context self._context = None - self._actions = actions + self._actions = actions or {} # Make sure that we actually match our trigger in case we are # immediately expanded. diff --git a/pythonx/UltiSnips/snippet_manager.py b/pythonx/UltiSnips/snippet_manager.py index 9e443e87..05a89d32 100644 --- a/pythonx/UltiSnips/snippet_manager.py +++ b/pythonx/UltiSnips/snippet_manager.py @@ -4,14 +4,11 @@ """Contains the SnippetManager facade used by all Vim Functions.""" from collections import defaultdict -from functools import wraps +from contextlib import contextmanager import os import platform -import traceback import sys import vim -import re -from contextlib import contextmanager from UltiSnips import vim_helper from UltiSnips import err_to_scratch_buffer @@ -114,6 +111,7 @@ def jump_forwards(self): if not self._jump(): vim_helper.command("let g:ulti_jump_forwards_res = 0") return self._handle_failure(self.forward_trigger) + return None @err_to_scratch_buffer.wrap def jump_backwards(self): @@ -123,6 +121,7 @@ def jump_backwards(self): if not self._jump(True): vim_helper.command("let g:ulti_jump_backwards_res = 0") return self._handle_failure(self.backward_trigger) + return None @err_to_scratch_buffer.wrap def expand(self): @@ -151,10 +150,10 @@ def expand_or_jump(self): self._handle_failure(self.expand_trigger) @err_to_scratch_buffer.wrap - def snippets_in_current_scope(self, searchAll): + def snippets_in_current_scope(self, search_all): """Returns the snippets that could be expanded to Vim as a global variable.""" - before = "" if searchAll else vim_helper.buf.line_till_cursor + before = "" if search_all else vim_helper.buf.line_till_cursor snippets = self._snips(before, True) # Sort snippets alphabetically @@ -180,7 +179,7 @@ def snippets_in_current_scope(self, searchAll): ) ) - if searchAll: + if search_all: vim_helper.command( as_unicode( ( @@ -231,7 +230,7 @@ def add_snippet( ft="all", priority=0, context=None, - actions={}, + actions=None, ): """Add a snippet to the list of known snippets of the given 'ft'.""" self._added_snippets_source.add_snippet( @@ -251,7 +250,7 @@ def add_snippet( @err_to_scratch_buffer.wrap def expand_anon( - self, value, trigger="", description="", options="", context=None, actions={} + self, value, trigger="", description="", options="", context=None, actions=None ): """Expand an anonymous snippet right here.""" before = vim_helper.buf.line_till_cursor @@ -262,8 +261,7 @@ def expand_anon( if not trigger or snip.matches(before, self._visual_content): self._do_snippet(snip, before) return True - else: - return False + return False def register_snippet_source(self, name, snippet_source): """Registers a new 'snippet_source' with the given 'name'. @@ -294,10 +292,10 @@ def get_buffer_filetypes(self): + ["all"] ) - def add_buffer_filetypes(self, ft): + def add_buffer_filetypes(self, filetypes): buf_fts = self._added_buffer_filetypes[vim_helper.buf.number] idx = -1 - for ft in ft.split("."): + for ft in filetypes.split("."): ft = ft.strip() if not ft: continue @@ -468,7 +466,7 @@ def _leaving_buffer(self): terminated. """ - while len(self._active_snippets): + while self._active_snippets: self._current_snippet_is_done() self._reinit() @@ -612,10 +610,7 @@ def _handle_failure(self, trigger): # Use remap mode so SuperTab mappings will be invoked. break - if ( - feedkey == r"\SuperTabForward" - or feedkey == r"\SuperTabBackward" - ): + if feedkey in (r"\SuperTabForward", r"\SuperTabBackward"): vim_helper.command("return SuperTab(%s)" % vim_helper.escape(mode)) elif feedkey: vim_helper.command("return %s" % vim_helper.escape(feedkey)) @@ -774,7 +769,7 @@ def _try_expand(self, autotrigger_only=False): @property def _current_snippet(self): """The current snippet or None.""" - if not len(self._active_snippets): + if not self._active_snippets: return None return self._active_snippets[-1]