Fix pylint

This also reverts commit 8df0b063be.
This commit is contained in:
Florian Bruhin 2017-07-04 15:33:58 +02:00
parent 88b878098d
commit cff61fa0bc
38 changed files with 93 additions and 75 deletions

View File

@ -22,7 +22,6 @@
import os
import sys
import subprocess
import configparser
import functools
import json
import shutil
@ -647,8 +646,8 @@ class Quitter:
"""Quit qutebrowser.
Args:
save: When given, save the open windows even if auto_save.session is
turned off.
save: When given, save the open windows even if auto_save.session
is turned off.
session: The name of the session to save.
"""
if session is not None and not save:

View File

@ -33,7 +33,7 @@ import pygments.lexers
import pygments.formatters
from qutebrowser.commands import userscripts, cmdexc, cmdutils, runners
from qutebrowser.config import config, configexc, configdata
from qutebrowser.config import config, configdata
from qutebrowser.browser import (urlmarks, browsertab, inspector, navigate,
webelem, downloads)
from qutebrowser.keyinput import modeman

View File

@ -472,10 +472,12 @@ class AbstractDownloadItem(QObject):
position: The color type requested, can be 'fg' or 'bg'.
"""
assert position in ["fg", "bg"]
# pylint: disable=bad-config-option
start = getattr(config.val.colors.downloads.start, position)
stop = getattr(config.val.colors.downloads.stop, position)
system = getattr(config.val.colors.downloads.system, position)
error = getattr(config.val.colors.downloads.error, position)
# pylint: enable=bad-config-option
if self.error_msg is not None:
assert not self.successful
return error

View File

@ -83,7 +83,10 @@ def _find_prevnext(prev, elems):
option = 'prev_regexes' if prev else 'next_regexes'
if not elems:
return None
# pylint: disable=bad-config-option
for regex in getattr(config.val.hints, option):
# pylint: enable=bad-config-option
log.hints.vdebug("== Checking regex '{}'.".format(regex.pattern))
for e in elems:
text = str(e)

View File

@ -249,6 +249,7 @@ class PACFetcher(QObject):
self._manager.setProxy(QNetworkProxy(QNetworkProxy.NoProxy))
self._pac = None
self._error_message = None
self._reply = None
def __eq__(self, other):
# pylint: disable=protected-access

View File

@ -40,7 +40,8 @@ def custom_headers():
headers[b'DNT'] = dnt
headers[b'X-Do-Not-Track'] = dnt
for header, value in config.val.content.headers.custom.items():
conf_headers = config.val.content.headers.custom
for header, value in conf_headers.items():
headers[header.encode('ascii')] = value.encode('ascii')
accept_language = config.val.content.headers.accept_language

View File

@ -21,12 +21,11 @@
import mimetypes
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtNetwork import QNetworkReply
from qutebrowser.browser import pdfjs, qutescheme
from qutebrowser.browser.webkit.network import schemehandler, networkreply
from qutebrowser.utils import jinja, log, message, usertypes, qtutils
from qutebrowser.utils import log, usertypes, qtutils
class QuteSchemeHandler(schemehandler.SchemeHandler):

View File

@ -27,7 +27,6 @@ import sip
from PyQt5.QtCore import (pyqtSlot, Qt, QEvent, QUrl, QPoint, QTimer, QSizeF,
QSize)
from PyQt5.QtGui import QKeyEvent
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebKitWidgets import QWebPage, QWebFrame
from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtPrintSupport import QPrinter

View File

@ -25,7 +25,7 @@ from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QUrl
from PyQt5.QtGui import QPalette
from PyQt5.QtWidgets import QStyleFactory
from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtWebKitWidgets import QWebView, QWebPage, QWebFrame
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
from qutebrowser.config import config
from qutebrowser.keyinput import modeman

View File

@ -19,6 +19,9 @@
"""CompletionModels for the config."""
# FIXME:conf
# pylint: disable=no-member
from PyQt5.QtCore import pyqtSlot, Qt
from qutebrowser.config import config, configdata

View File

@ -19,6 +19,9 @@
"""Misc. CompletionModels."""
# FIXME:conf
# pylint: disable=unused-argument
from PyQt5.QtCore import Qt, QTimer, pyqtSlot
from qutebrowser.browser import browsertab

View File

@ -20,15 +20,13 @@
"""Configuration storage and config-related utilities."""
import copy
import os.path
import contextlib
import functools
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject, QUrl
from qutebrowser.config import configdata, configexc, configtypes, configfiles
from qutebrowser.utils import (utils, objreg, message, standarddir, log,
usertypes)
from qutebrowser.utils import utils, objreg, message, log, usertypes
from qutebrowser.misc import objects
from qutebrowser.commands import cmdexc, cmdutils
@ -279,8 +277,8 @@ class ConfigCommands:
def _print_value(self, option):
"""Print the value of the given option."""
with self._handle_config_error():
val = self._config.get_str(option)
message.info("{} = {}".format(option, val))
value = self._config.get_str(option)
message.info("{} = {}".format(option, value))
def _set_next(self, option, values, *, temp):
"""Set the next value out of a list of values."""
@ -292,9 +290,9 @@ class ConfigCommands:
# Use the next valid value from values, or the first if the current
# value does not appear in the list
val = self._config.get_str(option)
old_value = self._config.get_str(option)
try:
idx = values.index(str(val))
idx = values.index(str(old_value))
idx = (idx + 1) % len(values)
value = values[idx]
except ValueError:

View File

@ -27,7 +27,6 @@ DATA: A dict of Option objects after init() has been called.
# FIXME:conf reintroduce interpolation?
import sys
import re
import collections
import functools

View File

@ -170,7 +170,10 @@ class BaseType:
self._basic_str_validation(value)
def _basic_str_validation(self, value):
"""Do some basic validation for string values (empty, non-printable chars).
"""Do some basic validation for string values.
This checks that the value isn't empty and doesn't contain any
unprintable chars.
Arguments:
value: The value to check.
@ -211,9 +214,9 @@ class BaseType:
def from_str(self, value):
"""Get the setting value from a string.
By default this invokes to_py() for validation and returns the unaltered
value. This means that if to_py() returns a string rather than something
more sophisticated, this doesn't need to be implemented.
By default this invokes to_py() for validation and returns the
unaltered value. This means that if to_py() returns a string rather
than something more sophisticated, this doesn't need to be implemented.
Args:
value: The original string value.
@ -256,6 +259,7 @@ class BaseType:
This currently uses asciidoc syntax.
"""
utils.unused(indent) # only needed for Dict/List
if not value:
return 'empty'
return '+pass:[{}]+'.format(html.escape(self.to_str(value)))

View File

@ -23,10 +23,10 @@ import re
import functools
import unicodedata
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject
from PyQt5.QtCore import pyqtSignal, QObject
from qutebrowser.config import config
from qutebrowser.utils import usertypes, log, utils, objreg
from qutebrowser.utils import usertypes, log, utils
class BaseKeyParser(QObject):
@ -190,7 +190,8 @@ class BaseKeyParser(QObject):
return self.Match.none
self._stop_timers()
txt = config.val.bindings.key_mappings.get(txt, txt)
key_mappings = config.val.bindings.key_mappings
txt = key_mappings.get(txt, txt)
self._keystring += txt
count, cmd_input = self._split_count()

View File

@ -65,7 +65,8 @@ class Message(QLabel):
raise ValueError("Invalid level {!r}".format(level))
# We don't bother with set_register_stylesheet here as it's short-lived
# anyways.
config.set_register_stylesheet(self, stylesheet=stylesheet, update=False)
config.set_register_stylesheet(self, stylesheet=stylesheet,
update=False)
class MessageView(QWidget):

View File

@ -176,7 +176,8 @@ class TabbedBrowser(tabwidget.TabWidget):
fields = self.get_tab_fields(idx)
fields['id'] = self._win_id
title = config.val.window.title_format.format(**fields)
title_format = config.val.window.title_format
title = title_format.format(**fields)
self.window().setWindowTitle(title)
def _connect_tab_signals(self, tab):

View File

@ -546,15 +546,15 @@ class TabBar(QTabBar):
def paintEvent(self, _e):
"""Override paintEvent to draw the tabs like we want to."""
# pylint: disable=bad-config-call
# WORKAROUND for https://bitbucket.org/logilab/astroid/issue/104
p = QStylePainter(self)
selected = self.currentIndex()
for idx in range(self.count()):
tab = QStyleOptionTab()
self.initStyleOption(tab, idx)
# pylint: disable=bad-config-option
setting = config.val.colors.tabs
# pylint: enable=bad-config-option
if idx == selected:
setting = setting.selected
setting = setting.odd if idx % 2 else setting.even

View File

@ -31,7 +31,7 @@ from PyQt5.QtWidgets import QLabel, QSizePolicy
from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt
from qutebrowser.config import config
from qutebrowser.utils import objreg, utils, usertypes
from qutebrowser.utils import utils, usertypes
class KeyHintView(QLabel):

View File

@ -864,6 +864,11 @@ def open_file(filename, cmdline=None):
proc.start_detached(cmd, args)
def unused(_arg):
"""Function which does nothing to avoid pylint complaining."""
pass
def expand_windows_drive(path):
r"""Expand a drive-path like E: into E:\.

View File

@ -40,20 +40,17 @@ class ConfigChecker(checkers.BaseChecker):
name = 'config'
msgs = {
'E9998': ('%s is no valid config option.', # flake8: disable=S001
'bad-config-call',
None),
'E9999': ('old config call', # flake8: disable=S001
'old-config-call',
'bad-config-option',
None),
}
priority = -1
@utils.check_messages('bad-config-call')
@utils.check_messages('bad-config-option')
def visit_attribute(self, node):
"""Visit a getattr node."""
# At the end of a config.val.foo.bar chain
if not isinstance(node.parent, astroid.Attribute):
# FIXME do some proper check for this...
# FIXME:conf do some proper check for this...
node_str = node.as_string()
prefix = 'config.val.'
if node_str.startswith(prefix):
@ -62,7 +59,7 @@ class ConfigChecker(checkers.BaseChecker):
def _check_config(self, node, name):
"""Check that we're accessing proper config options."""
if name not in OPTIONS:
self.add_message('bad-config-call', node=node, args=name)
self.add_message('bad-config-option', node=node, args=name)
def register(linter):

View File

@ -22,7 +22,6 @@
import os
import sys
import html
import shutil
import os.path
import inspect

View File

@ -27,4 +27,5 @@ def invoke_with(quteproc):
quteproc.log_summary("Create a new window")
quteproc.send_ipc([], target_arg='window')
quteproc.wait_for(category='init', module='app',
function='_open_startpage', message='Opening start pages')
function='_open_startpage',
message='Opening start pages')

View File

@ -17,7 +17,5 @@
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
import pytest
import pytest_bdd as bdd
bdd.scenarios('keyinput.feature')

View File

@ -30,8 +30,7 @@ from PyQt5.QtNetwork import (QNetworkRequest, QAbstractNetworkCache,
from PyQt5.QtWidgets import QCommonStyle, QLineEdit, QWidget, QTabBar
from qutebrowser.browser import browsertab, history
from qutebrowser.config import configexc, configdata
from qutebrowser.utils import usertypes, utils
from qutebrowser.utils import usertypes
from qutebrowser.mainwindow import mainwindow

View File

@ -34,24 +34,24 @@ pytestmark = pytest.mark.usefixtures('qapp', 'config_tmpdir')
# TODO See ../utils/test_standarddirutils for OSError and caplog assertion
WHITELISTED_HOSTS = ['qutebrowser.org', 'mediumhost.io']
WHITELISTED_HOSTS = ('qutebrowser.org', 'mediumhost.io')
BLOCKLIST_HOSTS = ['localhost',
BLOCKLIST_HOSTS = ('localhost',
'mediumhost.io',
'malware.badhost.org',
'4-verybadhost.com',
'ads.worsthostever.net']
'ads.worsthostever.net')
CLEAN_HOSTS = ['goodhost.gov', 'verygoodhost.com']
CLEAN_HOSTS = ('goodhost.gov', 'verygoodhost.com')
URLS_TO_CHECK = ['http://localhost',
URLS_TO_CHECK = ('http://localhost',
'http://mediumhost.io',
'ftp://malware.badhost.org',
'http://4-verybadhost.com',
'http://ads.worsthostever.net',
'http://goodhost.gov',
'ftp://verygoodhost.com',
'http://qutebrowser.org']
'http://qutebrowser.org')
class BaseDirStub:
@ -374,7 +374,7 @@ def test_blocking_with_whitelist(config_stub, basedir, download_stub,
line_format='one_per_line')
config_stub.val.content.host_blocking.lists = [blocklist]
config_stub.val.content.host_blocking.enabled = True
config_stub.val.content.host_blocking.whitelist = WHITELISTED_HOSTS
config_stub.val.content.host_blocking.whitelist = list(WHITELISTED_HOSTS)
host_blocker = adblock.HostBlocker()
host_blocker.read_hosts()

View File

@ -42,7 +42,8 @@ class TestCommandParser:
with pytest.raises(cmdexc.NoSuchCommandError):
parser.parse_all(cmdline_test.cmd, aliases=False)
def test_parse_all_with_alias(self, cmdline_test, monkeypatch, config_stub):
def test_parse_all_with_alias(self, cmdline_test, monkeypatch,
config_stub):
if not cmdline_test.cmd:
pytest.skip("Empty command")

View File

@ -30,7 +30,8 @@ from qutebrowser.utils import usertypes
from qutebrowser.commands import command, cmdutils
pytestmark = pytest.mark.skip("FIXME:conf reintroduce after new completion is in")
pytestmark = pytest.mark.skip("FIXME:conf reintroduce after new completion "
"is in")
class FakeCompletionModel(QStandardItemModel):

View File

@ -22,7 +22,7 @@
import unittest.mock
import pytest
from PyQt5.QtGui import QStandardItem, QColor
from PyQt5.QtGui import QStandardItem
from qutebrowser.completion import completionwidget
from qutebrowser.completion.models import base, sortfilter

View File

@ -17,6 +17,9 @@
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
# FIXME:conf
# pylint: disable=undefined-variable
"""Tests for completion models."""
import collections
@ -31,7 +34,8 @@ from qutebrowser.completion.models import (miscmodels, urlmodel, configmodel,
from qutebrowser.browser import history
pytestmark = pytest.mark.skip("FIXME:conf reintroduce after new completion is in")
pytestmark = pytest.mark.skip("FIXME:conf reintroduce after new completion "
"is in")
def _check_completions(model, expected):

View File

@ -26,7 +26,7 @@ from PyQt5.QtCore import QObject, QUrl
from PyQt5.QtGui import QColor
from qutebrowser.commands import cmdexc
from qutebrowser.config import config, configdata, configexc, configfiles
from qutebrowser.config import config, configdata, configexc
from qutebrowser.utils import objreg, usertypes
from qutebrowser.misc import objects
@ -83,7 +83,7 @@ class TestChangeFilter:
was_called = True
foo = Foo()
foo.meth(changed)
foo.meth(changed) # pylint: disable=too-many-function-args
else:
@ -92,7 +92,7 @@ class TestChangeFilter:
nonlocal was_called
was_called = True
func(changed)
func(changed) # pylint: disable=too-many-function-args
assert was_called == matches
@ -127,7 +127,8 @@ class TestKeyConfig:
({'a': None}, {'b': 'message-info bar'}),
# Additional binding
({'c': 'message-info baz'},
{'a': 'message-info foo', 'b': 'message-info bar', 'c': 'message-info baz'}),
{'a': 'message-info foo', 'b': 'message-info bar',
'c': 'message-info baz'}),
# Unbinding unknown key
({'x': None}, {'a': 'message-info foo', 'b': 'message-info bar'}),
])
@ -638,8 +639,9 @@ class TestConfig:
When we get a mutable object from the config, some invariants should be
true:
- The object we get from the config is always a copy, i.e. mutating it
doesn't change the internal value (or default) stored in the config.
- The object we get from the config is always a copy, i.e. mutating
it doesn't change the internal value (or default) stored in the
config.
- If we mutate the object (mutated=True) and the config watches for
mutables (mutable=True), it should notice that the object changed.
- With mutable=False, we should always get the old object back.
@ -760,7 +762,7 @@ class TestContainer:
def test_getattr_invalid_private(self, container):
"""Make sure an invalid _attribute doesn't try getting a container."""
with pytest.raises(AttributeError):
container._foo
container._foo # pylint: disable=pointless-statement
def test_getattr_prefix(self, container):
new_container = container.tabs
@ -773,7 +775,7 @@ class TestContainer:
def test_getattr_invalid(self, container):
with pytest.raises(configexc.NoOptionError) as excinfo:
container.tabs.foobar
container.tabs.foobar # pylint: disable=pointless-statement
assert excinfo.value.option == 'tabs.foobar'
def test_setattr_option(self, config_stub, container):

View File

@ -24,7 +24,7 @@ import yaml
import pytest
# To run cmdutils.register decorators
from qutebrowser import app
from qutebrowser import app # pylint: disable=unused-import
from qutebrowser.config import configdata, configtypes
from qutebrowser.utils import usertypes

View File

@ -44,7 +44,8 @@ def test_state_config(fake_save_manager, data_tmpdir,
if insert:
state['general']['newval'] = '23'
if 'foobar' in (old_data or ''):
# WORKAROUND for https://github.com/PyCQA/pylint/issues/574
if 'foobar' in (old_data or ''): # pylint: disable=superfluous-parens
assert state['general']['foobar'] == '42'
state._save()
@ -81,7 +82,8 @@ def test_yaml_config(fake_save_manager, config_tmpdir, old_config, insert):
else:
assert lines[3] == 'global:'
if 'magenta' in (old_config or ''):
# WORKAROUND for https://github.com/PyCQA/pylint/issues/574
if 'magenta' in (old_config or ''): # pylint: disable=superfluous-parens
assert ' colors.hints.fg: magenta' in lines
if insert:
assert ' tabs.show: never' in lines

View File

@ -19,8 +19,6 @@
"""Tests for qutebrowser.config.configtypes."""
import re
import os
import sys
import json
import math
import collections
@ -187,7 +185,7 @@ class TestAll:
"""Various tests which apply to all available config types."""
def gen_classes():
def gen_classes(): # pylint: disable=no-method-argument
"""Yield all configtypes classes to test.
Not a method as it's used in decorators.

View File

@ -19,12 +19,8 @@
"""pytest fixtures for tests.keyinput."""
from unittest import mock
import pytest
from qutebrowser.utils import objreg
BINDINGS = {'prompt': {'<Ctrl-a>': 'message-info ctrla',
'a': 'message-info a',

View File

@ -21,11 +21,9 @@
import pytest
from PyQt5.QtGui import QIcon, QPixmap, QFont, QColor
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon, QPixmap
from qutebrowser.mainwindow import tabwidget
from qutebrowser.config import configtypes
from qutebrowser.utils import usertypes

View File

@ -19,7 +19,6 @@
"""Test the keyhint widget."""
from collections import OrderedDict
import pytest
from qutebrowser.misc.keyhintwidget import KeyHintView

View File

@ -922,6 +922,10 @@ class TestOpenFile:
m.assert_called_with(QUrl('file:///foo/bar'))
def test_unused():
utils.unused(None)
@pytest.mark.parametrize('path, expected', [
('E:', 'E:\\'),
('e:', 'e:\\'),