Convert all function annotations to dicts.
This commit is contained in:
parent
c4cd6fc56a
commit
fd6e56d7af
@ -470,7 +470,8 @@ class CommandDispatcher:
|
|||||||
self._open(url, tab, background, window)
|
self._open(url, tab, background, window)
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='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):
|
tab=False, bg=False, window=False):
|
||||||
"""Open typical prev/next links or navigate using the URL path.
|
"""Open typical prev/next links or navigate using the URL path.
|
||||||
|
|
||||||
@ -515,7 +516,8 @@ class CommandDispatcher:
|
|||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', hide=True,
|
@cmdutils.register(instance='command-dispatcher', hide=True,
|
||||||
scope='window')
|
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'.
|
"""Scroll the current tab by 'count * dx/dy'.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -531,7 +533,7 @@ class CommandDispatcher:
|
|||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', hide=True,
|
@cmdutils.register(instance='command-dispatcher', hide=True,
|
||||||
scope='window')
|
scope='window')
|
||||||
def scroll_perc(self, perc: float=None,
|
def scroll_perc(self, perc: {'type': float}=None,
|
||||||
horizontal: {'flag': 'x'}=False,
|
horizontal: {'flag': 'x'}=False,
|
||||||
count: {'special': 'count'}=None):
|
count: {'special': 'count'}=None):
|
||||||
"""Scroll to a specific percentage of the page.
|
"""Scroll to a specific percentage of the page.
|
||||||
@ -549,7 +551,8 @@ class CommandDispatcher:
|
|||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', hide=True,
|
@cmdutils.register(instance='command-dispatcher', hide=True,
|
||||||
scope='window')
|
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.
|
"""Scroll the frame page-wise.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -714,7 +717,7 @@ class CommandDispatcher:
|
|||||||
self._open(url, tab, bg, window)
|
self._open(url, tab, bg, window)
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='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):
|
count: {'special': 'count'}=None):
|
||||||
"""Select the tab given as argument/[count].
|
"""Select the tab given as argument/[count].
|
||||||
|
|
||||||
@ -739,7 +742,7 @@ class CommandDispatcher:
|
|||||||
idx))
|
idx))
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||||
def tab_move(self, direction: ('+', '-')=None,
|
def tab_move(self, direction: {'type': ('+', '-')}=None,
|
||||||
count: {'special': 'count'}=None):
|
count: {'special': 'count'}=None):
|
||||||
"""Move the current tab.
|
"""Move the current tab.
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ class Command:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
AnnotationInfo = collections.namedtuple('AnnotationInfo',
|
AnnotationInfo = collections.namedtuple('AnnotationInfo',
|
||||||
['kwargs', 'typ', 'name', 'flag',
|
['kwargs', 'type', 'name', 'flag',
|
||||||
'special'])
|
'special'])
|
||||||
ParamType = usertypes.enum('ParamType', ['flag', 'positional'])
|
ParamType = usertypes.enum('ParamType', ['flag', 'positional'])
|
||||||
|
|
||||||
@ -301,19 +301,16 @@ class Command:
|
|||||||
flag: The short name/flag if overridden.
|
flag: The short name/flag if overridden.
|
||||||
name: The long name 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}
|
'special': None}
|
||||||
if param.annotation is not inspect.Parameter.empty:
|
if param.annotation is not inspect.Parameter.empty:
|
||||||
log.commands.vdebug("Parsing annotation {}".format(
|
log.commands.vdebug("Parsing annotation {}".format(
|
||||||
param.annotation))
|
param.annotation))
|
||||||
if isinstance(param.annotation, dict):
|
for field in ('type', 'flag', 'name', 'special'):
|
||||||
for field in ('type', 'flag', 'name', 'special'):
|
if field in param.annotation:
|
||||||
if field in param.annotation:
|
info[field] = param.annotation[field]
|
||||||
info[field] = param.annotation[field]
|
del param.annotation[field]
|
||||||
del param.annotation[field]
|
info['kwargs'] = param.annotation
|
||||||
info['kwargs'] = param.annotation
|
|
||||||
else:
|
|
||||||
info['typ'] = param.annotation
|
|
||||||
return self.AnnotationInfo(**info)
|
return self.AnnotationInfo(**info)
|
||||||
|
|
||||||
def _get_type(self, param, annotation_info):
|
def _get_type(self, param, annotation_info):
|
||||||
@ -323,8 +320,8 @@ class Command:
|
|||||||
param: The inspect.Parameter to look at.
|
param: The inspect.Parameter to look at.
|
||||||
annotation_info: An AnnotationInfo tuple which overrides the type.
|
annotation_info: An AnnotationInfo tuple which overrides the type.
|
||||||
"""
|
"""
|
||||||
if annotation_info.typ is not None:
|
if annotation_info.type is not None:
|
||||||
return annotation_info.typ
|
return annotation_info.type
|
||||||
elif param.default is None or param.default is inspect.Parameter.empty:
|
elif param.default is None or param.default is inspect.Parameter.empty:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
|
@ -31,7 +31,7 @@ from qutebrowser.widgets import console
|
|||||||
|
|
||||||
|
|
||||||
@cmdutils.register(scope='window')
|
@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.
|
"""Execute a command after some time.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -61,7 +61,7 @@ def later(ms: int, *command, win_id: {'special': 'win_id'}):
|
|||||||
|
|
||||||
|
|
||||||
@cmdutils.register(scope='window')
|
@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.
|
"""Repeat a given command.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -77,7 +77,7 @@ def repeat(times: int, *command, win_id: {'special': 'win_id'}):
|
|||||||
|
|
||||||
|
|
||||||
@cmdutils.register(debug=True)
|
@cmdutils.register(debug=True)
|
||||||
def debug_crash(typ: ('exception', 'segfault')='exception'):
|
def debug_crash(typ: {'type': ('exception', 'segfault')}='exception'):
|
||||||
"""Crash for debugging purposes.
|
"""Crash for debugging purposes.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
Loading…
Reference in New Issue
Block a user