diff options
author | Shougo Matsushita <Shougo.Matsu@gmail.com> | 2019-08-04 10:16:18 +0900 |
---|---|---|
committer | Shougo Matsushita <Shougo.Matsu@gmail.com> | 2019-08-04 10:16:18 +0900 |
commit | 60df951aea7a750c6595b85f04f65be3b5f14f59 (patch) | |
tree | 8f3064e97b15c26b04e5b83ffeee068f229a47c2 /rplugin/python3 | |
parent | e8cab49ac99a5bb45e16a4bf24bb697163e7beaf (diff) | |
download | deoplete.nvim-60df951aea7a750c6595b85f04f65be3b5f14f59.zip |
Fix typing
Diffstat (limited to 'rplugin/python3')
-rw-r--r-- | rplugin/python3/deoplete/base/source.py | 38 | ||||
-rw-r--r-- | rplugin/python3/deoplete/filter/base.py | 3 | ||||
-rw-r--r-- | rplugin/python3/deoplete/source/base.py | 3 | ||||
-rw-r--r-- | rplugin/python3/deoplete/util.py | 24 |
4 files changed, 40 insertions, 28 deletions
diff --git a/rplugin/python3/deoplete/base/source.py b/rplugin/python3/deoplete/base/source.py index ed4eb84..89cff31 100644 --- a/rplugin/python3/deoplete/base/source.py +++ b/rplugin/python3/deoplete/base/source.py @@ -5,21 +5,24 @@ # ============================================================================ import re +import typing from abc import abstractmethod + from deoplete.logger import LoggingMixin -from deoplete.util import debug, error_vim +from deoplete.util import debug, error_vim, Nvim, UserContext, Candidates class Base(LoggingMixin): - def __init__(self, vim): + def __init__(self, vim: Nvim) -> None: self.vim = vim self.description = '' self.mark = '' + self.name = '' self.max_pattern_length = 80 self.min_pattern_length = -1 self.input_pattern = '' - self.input_patterns = {} + self.input_patterns: typing.Dict[str, str] = {} self.matchers = ['matcher_fuzzy'] self.sorters = ['sorter_rank'] self.converters = [ @@ -28,17 +31,17 @@ class Base(LoggingMixin): 'converter_truncate_kind', 'converter_truncate_info', 'converter_truncate_menu'] - self.filetypes = [] - self.keyword_patterns = [] + self.filetypes: typing.List[str] = [] + self.keyword_patterns: typing.List[str] = [] self.is_debug_enabled = False self.is_bytepos = False self.is_initialized = False self.is_volatile = False self.is_silent = False self.rank = 100 - self.disabled_syntaxes = [] + self.disabled_syntaxes: typing.List[str] = [] self.events = None - self.vars = {} + self.vars: typing.Dict[str, typing.Any] = {} self.max_abbr_width = 80 self.max_kind_width = 40 self.max_info_width = 200 @@ -47,27 +50,27 @@ class Base(LoggingMixin): self.matcher_key = '' self.dup = False - def get_complete_position(self, context): + def get_complete_position(self, context: UserContext) -> int: m = re.search('(?:' + context['keyword_pattern'] + ')$|$', context['input']) return m.start() if m else -1 - def print(self, expr): + def print(self, expr: typing.Any) -> None: if not self.is_silent: debug(self.vim, expr) - def print_error(self, expr): + def print_error(self, expr: typing.Any) -> None: if not self.is_silent: error_vim(self.vim, expr) @abstractmethod - def gather_candidates(self, context): - pass + def gather_candidates(self, context: UserContext) -> Candidates: + return [] - def on_event(self, context): + def on_event(self, context: UserContext) -> None: pass - def get_var(self, var_name): + def get_var(self, var_name: str) -> typing.Optional[typing.Any]: custom_vars = self.vim.call( 'deoplete#custom#_get_source_vars', self.name) if var_name in custom_vars: @@ -76,19 +79,20 @@ class Base(LoggingMixin): return self.vars[var_name] return None - def get_filetype_var(self, filetype, var_name): + def get_filetype_var(self, filetype: str, + var_name: str) -> typing.Optional[typing.Any]: var = self.get_var(var_name) if var is None: return None ft = filetype if (filetype in var) else '_' return var.get(ft, '') - def get_input_pattern(self, filetype): + def get_input_pattern(self, filetype: str) -> str: if not self.input_patterns: return self.input_pattern ft = filetype if (filetype in self.input_patterns) else '_' return self.input_patterns.get(ft, self.input_pattern) - def get_buf_option(self, option): + def get_buf_option(self, option: str) -> typing.Any: return self.vim.call('getbufvar', '%', '&' + option) diff --git a/rplugin/python3/deoplete/filter/base.py b/rplugin/python3/deoplete/filter/base.py index 4612630..7b89960 100644 --- a/rplugin/python3/deoplete/filter/base.py +++ b/rplugin/python3/deoplete/filter/base.py @@ -6,8 +6,9 @@ # For backward compatibility from deoplete.base.filter import Base as _Base +from deoplete.util import Nvim class Base(_Base): - def __init__(self, vim): + def __init__(self, vim: Nvim) -> None: super().__init__(vim) diff --git a/rplugin/python3/deoplete/source/base.py b/rplugin/python3/deoplete/source/base.py index cc061d4..0c59b5a 100644 --- a/rplugin/python3/deoplete/source/base.py +++ b/rplugin/python3/deoplete/source/base.py @@ -6,8 +6,9 @@ # For backward compatibility from deoplete.base.source import Base as _Base +from deoplete.util import Nvim class Base(_Base): - def __init__(self, vim): + def __init__(self, vim: Nvim) -> None: super().__init__(vim) diff --git a/rplugin/python3/deoplete/util.py b/rplugin/python3/deoplete/util.py index 97ce2cf..c343897 100644 --- a/rplugin/python3/deoplete/util.py +++ b/rplugin/python3/deoplete/util.py @@ -20,7 +20,9 @@ else: from neovim import Nvim from neovim.api import Buffer -Candidates = typing.Dict[str, typing.Any] +UserContext = typing.Dict[str, typing.Any] +Candidate = typing.Dict[str, typing.Any] +Candidates = typing.List[Candidate] def set_pattern(variable: typing.Dict[str, str], @@ -239,17 +241,19 @@ def binary_search_begin(l: typing.List[Candidates], prefix: str) -> int: if not l: return -1 if len(l) == 1: - return 0 if l[0]['word'].lower().startswith(prefix) else -1 + word = l[0]['word'] # type: ignore + return 0 if word.lower().startswith(prefix) else -1 s = 0 e = len(l) prefix = prefix.lower() while s < e: index = int((s + e) / 2) - word = l[index]['word'].lower() + word = l[index]['word'].lower() # type: ignore if word.startswith(prefix): - if (index - 1 < 0 or not - l[index-1]['word'].lower().startswith(prefix)): + if (index - 1) < 0: + return index + if l[index-1]['word'].lower().startswith(prefix): # type: ignore return index e = index elif prefix < word: @@ -263,17 +267,19 @@ def binary_search_end(l: typing.List[Candidates], prefix: str) -> int: if not l: return -1 if len(l) == 1: - return 0 if l[0]['word'].lower().startswith(prefix) else -1 + word = l[0]['word'] # type: ignore + return 0 if word.lower().startswith(prefix) else -1 s = 0 e = len(l) prefix = prefix.lower() while s < e: index = int((s + e) / 2) - word = l[index]['word'].lower() + word = l[index]['word'].lower() # type: ignore if word.startswith(prefix): - if ((index + 1) >= len(l) or not - l[index+1]['word'].lower().startswith(prefix)): + if (index + 1) >= len(l): + return index + if l[index+1]['word'].lower().startswith(prefix): # type: ignore return index s = index + 1 elif prefix < word: |