Add missing docstrings

This commit is contained in:
Florian Bruhin 2017-12-15 13:55:06 +01:00
parent 03a339b93a
commit 3f9ded3bed
20 changed files with 24 additions and 0 deletions

View File

@ -487,6 +487,7 @@ class AbstractHistory:
raise NotImplementedError raise NotImplementedError
def back(self, count=1): def back(self, count=1):
"""Go back in the tab's history."""
idx = self.current_idx() - count idx = self.current_idx() - count
if idx >= 0: if idx >= 0:
self._go_to_item(self._item_at(idx)) self._go_to_item(self._item_at(idx))
@ -495,6 +496,7 @@ class AbstractHistory:
raise WebTabError("At beginning of history.") raise WebTabError("At beginning of history.")
def forward(self, count=1): def forward(self, count=1):
"""Go forward in the tab's history."""
idx = self.current_idx() + count idx = self.current_idx() + count
if idx < len(self): if idx < len(self):
self._go_to_item(self._item_at(idx)) self._go_to_item(self._item_at(idx))

View File

@ -1522,6 +1522,7 @@ class CommandDispatcher:
dest = os.path.expanduser(dest) dest = os.path.expanduser(dest)
def callback(data): def callback(data):
"""Write the data to disk."""
try: try:
with open(dest, 'w', encoding='utf-8') as f: with open(dest, 'w', encoding='utf-8') as f:
f.write(data) f.write(data)
@ -2040,6 +2041,7 @@ class CommandDispatcher:
jseval_cb = None jseval_cb = None
else: else:
def jseval_cb(out): def jseval_cb(out):
"""Show the data returned from JS."""
if out is None: if out is None:
# Getting the actual error (if any) seems to be difficult. # Getting the actual error (if any) seems to be difficult.
# The error does end up in # The error does end up in

View File

@ -268,6 +268,7 @@ class WebHistory(sql.SqlTable):
return return
def action(): def action():
"""Actually run the import."""
with debug.log_time(log.init, 'Import old history file to sqlite'): with debug.log_time(log.init, 'Import old history file to sqlite'):
try: try:
self._read(path) self._read(path)

View File

@ -94,6 +94,7 @@ class AbstractWebInspector(QWidget):
raise NotImplementedError raise NotImplementedError
def toggle(self, page): def toggle(self, page):
"""Show/hide the inspector."""
if self._widget.isVisible(): if self._widget.isVisible():
self.hide() self.hide()
else: else:

View File

@ -59,6 +59,7 @@ def _js_slot(*args):
def _decorator(method): def _decorator(method):
@functools.wraps(method) @functools.wraps(method)
def new_method(self, *args, **kwargs): def new_method(self, *args, **kwargs):
"""Call the underlying function."""
try: try:
return method(self, *args, **kwargs) return method(self, *args, **kwargs)
except: except:

View File

@ -113,6 +113,7 @@ class add_handler: # noqa: N801,N806 pylint: disable=invalid-name
return function return function
def wrapper(self, *args, **kwargs): def wrapper(self, *args, **kwargs):
"""Call the underlying function."""
if self._backend is not None and objects.backend != self._backend: if self._backend is not None and objects.backend != self._backend:
return self.wrong_backend_handler(*args, **kwargs) return self.wrong_backend_handler(*args, **kwargs)
else: else:

View File

@ -226,6 +226,7 @@ class WebEngineElement(webelem.AbstractWebElement):
QEventLoop.ExcludeUserInputEvents) QEventLoop.ExcludeUserInputEvents)
def reset_setting(_arg): def reset_setting(_arg):
"""Set the JavascriptCanOpenWindows setting to its old value."""
try: try:
view.settings().setAttribute(attribute, could_open_windows) view.settings().setAttribute(attribute, could_open_windows)
except RuntimeError: except RuntimeError:

View File

@ -542,6 +542,7 @@ class WebKitElements(browsertab.AbstractElements):
def find_id(self, elem_id, callback): def find_id(self, elem_id, callback):
def find_id_cb(elems): def find_id_cb(elems):
"""Call the real callback with the found elements."""
if not elems: if not elems:
callback(None) callback(None)
else: else:

View File

@ -104,11 +104,13 @@ class change_filter: # noqa: N801,N806 pylint: disable=invalid-name
if self._function: if self._function:
@functools.wraps(func) @functools.wraps(func)
def wrapper(option=None): def wrapper(option=None):
"""Call the underlying function."""
if self._check_match(option): if self._check_match(option):
return func() return func()
else: else:
@functools.wraps(func) @functools.wraps(func)
def wrapper(wrapper_self, option=None): def wrapper(wrapper_self, option=None):
"""Call the underlying function."""
if self._check_match(option): if self._check_match(option):
return func(wrapper_self) return func(wrapper_self)

View File

@ -83,6 +83,7 @@ class NormalKeyParser(keyparser.CommandKeyParser):
return match return match
def set_inhibited_timeout(self, timeout): def set_inhibited_timeout(self, timeout):
"""Ignore keypresses for the given duration."""
if timeout != 0: if timeout != 0:
self._debug_log("Inhibiting the normal mode for {}ms.".format( self._debug_log("Inhibiting the normal mode for {}ms.".format(
timeout)) timeout))

View File

@ -818,6 +818,7 @@ class TabbedBrowser(tabwidget.TabWidget):
point, url = self._global_marks[key] point, url = self._global_marks[key]
def callback(ok): def callback(ok):
"""Scroll once loading finished."""
if ok: if ok:
self.cur_load_finished.disconnect(callback) self.cur_load_finished.disconnect(callback)
tab.scroller.to_point(point) tab.scroller.to_point(point)

View File

@ -364,6 +364,7 @@ def _check_backend_modules():
def init(): def init():
"""Check for various issues related to QtWebKit/QtWebEngine."""
_check_backend_modules() _check_backend_modules()
if objects.backend == usertypes.Backend.QtWebEngine: if objects.backend == usertypes.Backend.QtWebEngine:
_handle_ssl_support() _handle_ssl_support()

View File

@ -261,6 +261,7 @@ def init_log(args):
def check_optimize_flag(): def check_optimize_flag():
"""Check whether qutebrowser is running with -OO."""
from qutebrowser.utils import log from qutebrowser.utils import log
if sys.flags.optimize >= 2: if sys.flags.optimize >= 2:
log.init.warning("Running on optimize level higher than 1, " log.init.warning("Running on optimize level higher than 1, "

View File

@ -266,6 +266,7 @@ class log_time: # noqa: N801,N806 pylint: disable=invalid-name
def __call__(self, func): def __call__(self, func):
@functools.wraps(func) @functools.wraps(func)
def wrapped(*args, **kwargs): def wrapped(*args, **kwargs):
"""Call the original function."""
with self: with self:
func(*args, **kwargs) func(*args, **kwargs)

View File

@ -216,6 +216,7 @@ class GlobalMessageBridge(QObject):
self.ask_question.emit(question, blocking) self.ask_question.emit(question, blocking)
def show(self, level, text, replace=False): def show(self, level, text, replace=False):
"""Show the given message."""
if self._connected: if self._connected:
self.show_message.emit(level, text, replace) self.show_message.emit(level, text, replace)
else: else:

View File

@ -631,6 +631,7 @@ class prevent_exceptions: # noqa: N801,N806 pylint: disable=invalid-name
@functools.wraps(func) @functools.wraps(func)
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
"""Call the original function."""
try: try:
return func(*args, **kwargs) return func(*args, **kwargs)
except BaseException: except BaseException:

View File

@ -66,6 +66,7 @@ class AsciiDoc:
shutil.rmtree(self._homedir) shutil.rmtree(self._homedir)
def build(self): def build(self):
"""Build either the website or the docs."""
if self._args.website: if self._args.website:
self._build_website() self._build_website()
else: else:

View File

@ -40,6 +40,7 @@ def print_header():
def print_paths(): def print_paths():
"""Print all QStandardPaths.StandardLocation members."""
for name, obj in vars(QStandardPaths).items(): for name, obj in vars(QStandardPaths).items():
if isinstance(obj, QStandardPaths.StandardLocation): if isinstance(obj, QStandardPaths.StandardLocation):
location = QStandardPaths.writableLocation(obj) location = QStandardPaths.writableLocation(obj)

View File

@ -233,6 +233,7 @@ def install(languages):
def update(languages): def update(languages):
"""Update the given languages."""
installed = [lang for lang in languages if lang.local_version is not None] installed = [lang for lang in languages if lang.local_version is not None]
for lang in installed: for lang in installed:
if lang.local_version < lang.remote_version: if lang.local_version < lang.remote_version:
@ -244,6 +245,7 @@ def update(languages):
def remove_old(languages): def remove_old(languages):
"""Remove old versions of languages."""
installed = [lang for lang in languages if lang.local_version is not None] installed = [lang for lang in languages if lang.local_version is not None]
for lang in installed: for lang in installed:
local_files = spell.local_files(lang.code) local_files = spell.local_files(lang.code)

View File

@ -332,6 +332,7 @@ def import_chrome(profile, bookmark_types, output_format):
bookmarks = json.load(f) bookmarks = json.load(f)
def bm_tree_walk(bm, template): def bm_tree_walk(bm, template):
"""Recursive function to walk through bookmarks."""
assert 'type' in bm, bm assert 'type' in bm, bm
if bm['type'] == 'url': if bm['type'] == 'url':
if urllib.parse.urlparse(bm['url']).scheme != 'chrome': if urllib.parse.urlparse(bm['url']).scheme != 'chrome':