Update for new pylint/astroid releases

- Add a couple new "raise utils.Unreachable" to avoid
  possibly-used-before-assignment issues.
- Simplify an "if" for the same reason
- Remove an unneeded "return"
- Use "NoReturn" to prepare for pylint knowing about it in the future:
  https://github.com/pylint-dev/pylint/issues/9674
- Add some ignores for used-before-assignment false-positives
- Ignore new undefined-variable messages for Qt wrapers
- Ignore a new no-member warning for KeySequence:
  https://github.com/pylint-dev/astroid/issues/2448#issuecomment-2130124755
This commit is contained in:
Florian Bruhin 2024-05-24 21:37:15 +02:00
parent 1d8a2acf77
commit 72d7e2327b
15 changed files with 30 additions and 8 deletions

View File

@ -948,6 +948,8 @@ class CommandDispatcher:
"No window specified and couldn't find active window!")
assert isinstance(active_win, mainwindow.MainWindow), active_win
win_id = active_win.win_id
else:
raise utils.Unreachable(index_parts)
if win_id not in objreg.window_registry:
raise cmdutils.CommandError(

View File

@ -1477,9 +1477,9 @@ class WebEngineTab(browsertab.AbstractTab):
log.network.debug("Asking for credentials")
answer = shared.authentication_required(
url, authenticator, abort_on=[self.abort_questions])
if not netrc_success and answer is None:
log.network.debug("Aborting auth")
sip.assign(authenticator, QAuthenticator())
if answer is None:
log.network.debug("Aborting auth")
sip.assign(authenticator, QAuthenticator())
@pyqtSlot()
def _on_load_started(self):

View File

@ -330,7 +330,6 @@ class _WindowsUserscriptRunner(_BaseUserscriptRunner):
self._filepath = handle.name
except OSError as e:
message.error("Error while creating tempfile: {}".format(e))
return
class Error(Exception):

View File

@ -10,7 +10,7 @@ DATA: A dict of Option objects after init() has been called.
"""
from typing import (Any, Dict, Iterable, List, Mapping, MutableMapping, Optional,
Sequence, Tuple, Union, cast)
Sequence, Tuple, Union, NoReturn, cast)
import functools
import dataclasses
@ -57,7 +57,7 @@ class Migrations:
deleted: List[str] = dataclasses.field(default_factory=list)
def _raise_invalid_node(name: str, what: str, node: Any) -> None:
def _raise_invalid_node(name: str, what: str, node: Any) -> NoReturn:
"""Raise an exception for an invalid configdata YAML node.
Args:
@ -94,6 +94,7 @@ def _parse_yaml_type(
_raise_invalid_node(name, 'type', node)
try:
# pylint: disable=possibly-used-before-assignment
typ = getattr(configtypes, type_name)
except AttributeError:
raise AttributeError("Did not find type {} for {}".format(

View File

@ -359,6 +359,8 @@ class KeyInfo:
modifier_classes = (Qt.KeyboardModifier, Qt.KeyboardModifiers)
elif machinery.IS_QT6:
modifier_classes = Qt.KeyboardModifier
else:
raise utils.Unreachable()
assert isinstance(self.key, Qt.Key), self.key
assert isinstance(self.modifiers, modifier_classes), self.modifiers

View File

@ -27,6 +27,7 @@ else:
if machinery.IS_QT5:
# pylint: disable=undefined-variable
# moved to WebEngineCore in Qt 6
del QWebEngineSettings
del QWebEngineProfile

View File

@ -26,4 +26,5 @@ else:
raise machinery.UnknownWrapper()
if machinery.IS_QT5:
# pylint: disable=undefined-variable
del QFileSystemModel # moved to QtGui in Qt 6

View File

@ -905,6 +905,7 @@ def test_sandboxing(
f"{bpf_text} supports TSYNC": "Yes" if has_seccomp else "No",
f"{yama_text} (Broker)": "Yes" if has_yama else "No",
# pylint: disable-next=used-before-assignment
f"{yama_text} (Non-broker)": "Yes" if has_yama_non_broker else "No",
}

View File

@ -9,7 +9,7 @@ import pytest
from qutebrowser.qt.core import QUrl
from qutebrowser.browser import pdfjs
from qutebrowser.utils import urlmatch
from qutebrowser.utils import urlmatch, utils
pytestmark = [pytest.mark.usefixtures('data_tmpdir')]
@ -154,6 +154,8 @@ def test_read_from_system(names, expected_name, tmpdir):
expected = (b'text2', str(file2))
elif expected_name is None:
expected = (None, None)
else:
raise utils.Unreachable(expected_name)
assert pdfjs._read_from_system(str(tmpdir), names) == expected

View File

@ -29,7 +29,7 @@ from qutebrowser.completion import completer
from qutebrowser.completion.models import (
configmodel, listcategory, miscmodels, urlmodel, filepathcategory)
from qutebrowser.config import configdata, configtypes
from qutebrowser.utils import usertypes
from qutebrowser.utils import usertypes, utils
from qutebrowser.mainwindow import tabbedbrowser
@ -417,6 +417,8 @@ def test_filesystem_completion(qtmodeltester, config_stub, info,
base = '~'
expected_1 = str(pathlib.Path('~') / 'file1.txt')
expected_2 = str(pathlib.Path('~') / 'file2.txt')
else:
raise utils.Unreachable(method)
config_stub.val.completion.open_categories = ['filesystem']
model = urlmodel.url(info=info)

View File

@ -840,6 +840,8 @@ class TestBind:
func = functools.partial(commands.bind, 0)
elif command == 'unbind':
func = commands.unbind
else:
raise utils.Unreachable(command)
with pytest.raises(cmdutils.CommandError, match=expected):
func(*args, **kwargs)

View File

@ -399,6 +399,7 @@ class TestYaml:
yaml._save()
if not insert and old_config is None:
data = {} # unused
lines = []
else:
data = autoconfig.read()

View File

@ -1602,6 +1602,8 @@ class TestDict:
valtype=configtypes.String(),
required_keys=['one', 'two'])
message = 'Required keys .*'
else:
raise utils.Unreachable(kind)
if ok:
expectation = testutils.nop_contextmanager()

View File

@ -115,10 +115,12 @@ class TestHintKeyParser:
seq = keyutils.KeySequence.parse(keychain)
assert len(seq) == 2
# pylint: disable-next=no-member
match = keyparser.handle(seq[0].to_event())
assert match == QKeySequence.SequenceMatch.PartialMatch
assert hintmanager.keystr == prefix
# pylint: disable-next=no-member
match = keyparser.handle(seq[1].to_event())
assert match == QKeySequence.SequenceMatch.ExactMatch
assert hintmanager.keystr == hint
@ -132,10 +134,12 @@ class TestHintKeyParser:
seq = keyutils.KeySequence.parse('ασ')
assert len(seq) == 2
# pylint: disable-next=no-member
match = keyparser.handle(seq[0].to_event())
assert match == QKeySequence.SequenceMatch.PartialMatch
assert hintmanager.keystr == 'a'
# pylint: disable-next=no-member
match = keyparser.handle(seq[1].to_event())
assert match == QKeySequence.SequenceMatch.ExactMatch
assert hintmanager.keystr == 'as'

View File

@ -758,8 +758,10 @@ class TestPyQIODevice:
# pylint: enable=no-member,useless-suppression
else:
pytest.skip("Needs os.SEEK_HOLE or os.SEEK_DATA available.")
pyqiodev.open(QIODevice.OpenModeFlag.ReadOnly)
with pytest.raises(io.UnsupportedOperation):
# pylint: disable=possibly-used-before-assignment
pyqiodev.seek(0, whence)
@pytest.mark.flaky