Skip to content

Commit

Permalink
Fix lint and types
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdalisue committed Nov 25, 2016
1 parent 9bef6aa commit ea4837d
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 14 deletions.
5 changes: 3 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
__author__ = "lambdalisue"
__license__ = "MIT"
"""A prompt library for rplugin in Neovim."""
__author__ = 'lambdalisue'
__license__ = 'MIT'
11 changes: 10 additions & 1 deletion action.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
"""Action module."""
import re
from .digraph import Digraph
from .util import int2char, int2repr, getchar
from .util import getchar, int2char, int2repr


ACTION_PATTERN = re.compile(
r'(?P<namespace>\w+):(?P<name>\w+)(?::(?P<params>\w+))*'
)


class Action:
Expand All @@ -17,6 +22,10 @@ def __init__(self):
"""Constructor."""
self.registry = {}

def clear(self):
"""Clear registered actions."""
self.registry.clear()

def register(self, name, callback):
"""Register action callback to a specified name.
Expand Down
2 changes: 2 additions & 0 deletions action.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ ActionRules = Sequence[Tuple[str, ActionCallback]]
class Action:
registry = ... # type: Dict[str, ActionCallback]

def clear(self) -> None: ...

def register(self, name: str, callback: ActionCallback=None) -> None: ...

def register_from_rules(self, rules: ActionRules) -> None: ...
Expand Down
1 change: 1 addition & 0 deletions digraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Digraph(metaclass=Singleton):
__slots__ = ('registry',)

def __init__(self):
"""Constructor."""
self.registry = None

def find(self, nvim, char1, char2):
Expand Down
3 changes: 2 additions & 1 deletion key.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class Key(KeyBase):
__cached = {}

def __str__(self):
"""Return string representation of the key."""
return self.char

@classmethod
Expand All @@ -134,7 +135,7 @@ def represent(cls, nvim, code):

@classmethod
def parse(cls, nvim, expr):
"""Parse a key expression and return a Key instance.
r"""Parse a key expression and return a Key instance.
It returns a Key instance of a key expression. The instance is cached
to individual expression so that the instance is exactly equal when
Expand Down
6 changes: 4 additions & 2 deletions keymap.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Keymap."""
import time
from collections import namedtuple
from operator import itemgetter
from datetime import datetime
from operator import itemgetter
from .key import Key
from .keystroke import Keystroke
from .util import getchar
Expand All @@ -23,6 +23,7 @@ class Definition(DefinitionBase):
__slots__ = ()

def __new__(cls, lhs, rhs, noremap=False, nowait=False, expr=False):
"""Create a new instance of the definition."""
if expr and not isinstance(rhs, str):
raise AttributeError(
'"rhs" of "expr" mapping requires to be a str.'
Expand Down Expand Up @@ -322,7 +323,8 @@ def harvest(self, nvim, timeoutlen, callback=None):
while True:
code = _getcode(
nvim,
datetime.now() + timeoutlen if timeoutlen else None
datetime.now() + timeoutlen if timeoutlen else None,
callback=callback,
)
if code is None and previous is None:
# timeout without input
Expand Down
4 changes: 2 additions & 2 deletions keymap.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Keymap:
nowait: bool=False) -> Optional[Keystroke]: ...

def harvest(self, nvim: Nvim,
timeoutlen: Optional[int]=None,
timeoutlen: Optional[int],
callback: Optional[Callable]) -> Keystroke: ...

@classmethod
Expand All @@ -55,4 +55,4 @@ class Keymap:

def _getcode(nvim: Nvim,
timeout: Optional[datetime],
callback: Optional[Callback]) -> Optional[KeyCode]: ...
callback: Optional[Callable]) -> Optional[KeyCode]: ...
3 changes: 2 additions & 1 deletion keystroke.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Keystroke(tuple):
__slots__ = ()

def __str__(self):
"""Return a string representation of the keystroke."""
return ''.join(str(k) for k in self)

def startswith(self, other):
Expand All @@ -31,7 +32,7 @@ def startswith(self, other):

@classmethod
def parse(cls, nvim, expr):
"""Parse a keystroke expression and return a Keystroke instance.
r"""Parse a keystroke expression and return a Keystroke instance.
Args:
nvim (neovim.Nvim): A ``neovim.Nvim`` instance.
Expand Down
8 changes: 4 additions & 4 deletions prompt.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Prompt module."""
import re
import copy
import re
from datetime import timedelta
from .util import build_echon_expr, ESCAPE_ECHO
from .util import ESCAPE_ECHO, build_echon_expr

ACTION_KEYSTROKE_PATTERN = re.compile(r'<(\w+:\w+)>')

Expand Down Expand Up @@ -176,6 +176,7 @@ def update_text(self, text):
self.replace_text(text)

def redraw_prompt(self):
"""Redraw prompt."""
# NOTE:
# There is a highlight name 'Cursor' but some sometime the visibility
# is quite low (e.g. tender) so use 'IncSearch' instead while the
Expand Down Expand Up @@ -281,8 +282,7 @@ def on_keypress(self, keystroke):
It is used to handle a pressed keystroke. Note that subclass should NOT
override this method to perform actions. Register a new custom action
instead. In default, it call action and return the result if the
keystroke is <xxx:xxx>or call Vim function XXX and return the result
if the keystroke is <call:XXX>.
keystroke is <xxx:xxx>.
Args:
keystroke (Keystroke): A pressed keystroke instance. Note that this
Expand Down
3 changes: 2 additions & 1 deletion util.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def int2char(nvim, code):


def int2repr(nvim, code):
"""Return a string representation of a key with specified key code."""
from .key import Key
if isinstance(code, int):
return int2char(nvim, code)
Expand Down Expand Up @@ -183,7 +184,7 @@ class Singleton(type):

instance = None

def __call__(cls, *args, **kwargs):
def __call__(cls, *args, **kwargs): # noqa
if not cls.instance:
cls.instance = super().__call__(*args, **kwargs)
return cls.instance

0 comments on commit ea4837d

Please sign in to comment.