From fd6e56d7af177e84bd943366bdef7a421f4ff3c0 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 20 Oct 2014 17:20:39 +0200 Subject: [PATCH] Convert all function annotations to dicts. --- qutebrowser/browser/commands.py | 15 +++++++++------ qutebrowser/commands/command.py | 21 +++++++++------------ qutebrowser/utils/utilcmds.py | 6 +++--- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 6b7fc386d..4643e283f 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -470,7 +470,8 @@ class CommandDispatcher: self._open(url, tab, background, window) @cmdutils.register(instance='command-dispatcher', scope='window') - def navigate(self, where: ('prev', 'next', 'up', 'increment', 'decrement'), + def navigate(self, where: {'type': ('prev', 'next', 'up', 'increment', + 'decrement')}, tab=False, bg=False, window=False): """Open typical prev/next links or navigate using the URL path. @@ -515,7 +516,8 @@ class CommandDispatcher: @cmdutils.register(instance='command-dispatcher', hide=True, scope='window') - def scroll(self, dx: float, dy: float, count: {'special': 'count'}=1): + def scroll(self, dx: {'type': float}, dy: {'type': float}, + count: {'special': 'count'}=1): """Scroll the current tab by 'count * dx/dy'. Args: @@ -531,7 +533,7 @@ class CommandDispatcher: @cmdutils.register(instance='command-dispatcher', hide=True, scope='window') - def scroll_perc(self, perc: float=None, + def scroll_perc(self, perc: {'type': float}=None, horizontal: {'flag': 'x'}=False, count: {'special': 'count'}=None): """Scroll to a specific percentage of the page. @@ -549,7 +551,8 @@ class CommandDispatcher: @cmdutils.register(instance='command-dispatcher', hide=True, scope='window') - def scroll_page(self, x: float, y: float, count: {'special': 'count'}=1): + def scroll_page(self, x: {'type': float}, y: {'type': float}, + count: {'special': 'count'}=1): """Scroll the frame page-wise. Args: @@ -714,7 +717,7 @@ class CommandDispatcher: self._open(url, tab, bg, window) @cmdutils.register(instance='command-dispatcher', scope='window') - def tab_focus(self, index: (int, 'last')=None, + def tab_focus(self, index: {'type': (int, 'last')}=None, count: {'special': 'count'}=None): """Select the tab given as argument/[count]. @@ -739,7 +742,7 @@ class CommandDispatcher: idx)) @cmdutils.register(instance='command-dispatcher', scope='window') - def tab_move(self, direction: ('+', '-')=None, + def tab_move(self, direction: {'type': ('+', '-')}=None, count: {'special': 'count'}=None): """Move the current tab. diff --git a/qutebrowser/commands/command.py b/qutebrowser/commands/command.py index fe2d41d58..8bce98e01 100644 --- a/qutebrowser/commands/command.py +++ b/qutebrowser/commands/command.py @@ -59,7 +59,7 @@ class Command: """ AnnotationInfo = collections.namedtuple('AnnotationInfo', - ['kwargs', 'typ', 'name', 'flag', + ['kwargs', 'type', 'name', 'flag', 'special']) ParamType = usertypes.enum('ParamType', ['flag', 'positional']) @@ -301,19 +301,16 @@ class Command: flag: The short name/flag if overridden. name: The long name if overridden. """ - info = {'kwargs': {}, 'typ': None, 'flag': None, 'name': None, + info = {'kwargs': {}, 'type': None, 'flag': None, 'name': None, 'special': None} if param.annotation is not inspect.Parameter.empty: log.commands.vdebug("Parsing annotation {}".format( param.annotation)) - if isinstance(param.annotation, dict): - for field in ('type', 'flag', 'name', 'special'): - if field in param.annotation: - info[field] = param.annotation[field] - del param.annotation[field] - info['kwargs'] = param.annotation - else: - info['typ'] = param.annotation + for field in ('type', 'flag', 'name', 'special'): + if field in param.annotation: + info[field] = param.annotation[field] + del param.annotation[field] + info['kwargs'] = param.annotation return self.AnnotationInfo(**info) def _get_type(self, param, annotation_info): @@ -323,8 +320,8 @@ class Command: param: The inspect.Parameter to look at. annotation_info: An AnnotationInfo tuple which overrides the type. """ - if annotation_info.typ is not None: - return annotation_info.typ + if annotation_info.type is not None: + return annotation_info.type elif param.default is None or param.default is inspect.Parameter.empty: return None else: diff --git a/qutebrowser/utils/utilcmds.py b/qutebrowser/utils/utilcmds.py index 9bc7b9054..bebe7cdc5 100644 --- a/qutebrowser/utils/utilcmds.py +++ b/qutebrowser/utils/utilcmds.py @@ -31,7 +31,7 @@ from qutebrowser.widgets import console @cmdutils.register(scope='window') -def later(ms: int, *command, win_id: {'special': 'win_id'}): +def later(ms: {'type': int}, *command, win_id: {'special': 'win_id'}): """Execute a command after some time. Args: @@ -61,7 +61,7 @@ def later(ms: int, *command, win_id: {'special': 'win_id'}): @cmdutils.register(scope='window') -def repeat(times: int, *command, win_id: {'special': 'win_id'}): +def repeat(times: {'type': int}, *command, win_id: {'special': 'win_id'}): """Repeat a given command. Args: @@ -77,7 +77,7 @@ def repeat(times: int, *command, win_id: {'special': 'win_id'}): @cmdutils.register(debug=True) -def debug_crash(typ: ('exception', 'segfault')='exception'): +def debug_crash(typ: {'type': ('exception', 'segfault')}='exception'): """Crash for debugging purposes. Args: