mypy: Turn on warn_unreachable

This commit is contained in:
Florian Bruhin 2019-07-23 10:54:04 +02:00
parent 9ed6aaaa16
commit 8fe68b7dc8
7 changed files with 13 additions and 8 deletions

View File

@ -17,6 +17,7 @@ disallow_untyped_decorators = True
# check_untyped_defs = True
# no_implicit_optional = True
# warn_return_any = True
warn_unreachable = True
# Other strictness flags
strict_equality = True

View File

@ -172,7 +172,8 @@ class WebKitElement(webelem.AbstractWebElement):
def _parent(self) -> typing.Optional['WebKitElement']:
"""Get the parent element of this element."""
self._check_vanished()
elem = self._elem.parent()
elem = typing.cast(typing.Optional[QWebElement],
self._elem.parent())
if elem is None or elem.isNull():
return None
return WebKitElement(elem, tab=self._tab)

View File

@ -19,6 +19,7 @@
"""The tab widget used for TabbedBrowser from browser.py."""
import typing
import functools
import contextlib
@ -347,7 +348,8 @@ class TabWidget(QTabWidget):
def setTabIcon(self, idx: int, icon: QIcon):
"""Always show tab icons for pinned tabs in some circumstances."""
tab = self.widget(idx)
tab = typing.cast(typing.Optional[browsertab.AbstractTab],
self.widget(idx))
if (icon.isNull() and
config.cache['tabs.favicons.show'] != 'never' and
config.cache['tabs.pinned.shrink'] and

View File

@ -49,7 +49,8 @@ def check_python_version():
version_str = '.'.join(map(str, sys.version_info[:3]))
text = ("At least Python 3.5 is required to run qutebrowser, but " +
"it's running with " + version_str + ".\n")
if Tk and '--no-err-windows' not in sys.argv: # pragma: no cover
if (Tk and # type: ignore
'--no-err-windows' not in sys.argv): # pragma: no cover
root = Tk()
root.withdraw()
messagebox.showerror("qutebrowser: Fatal error!", text)

View File

@ -172,7 +172,7 @@ class CrashHandler(QObject):
if sys.__stderr__ is not None:
faulthandler.enable(sys.__stderr__)
else:
faulthandler.disable()
faulthandler.disable() # type: ignore
try:
self._crash_log_file.close()
os.remove(self._crash_log_file.name)

View File

@ -259,7 +259,7 @@ def _init_handlers(level, color, force_color, json_logging, ram_capacity):
level, color, force_color, json_logging)
if sys.stderr is None:
console_handler = None
console_handler = None # type: ignore
else:
strip = False if force_color else None
if use_colorama:
@ -313,7 +313,7 @@ def _init_formatters(level, color, force_color, json_logging):
html_formatter = HTMLFormatter(EXTENDED_FMT_HTML, DATEFMT,
log_colors=LOG_COLORS)
if sys.stderr is None:
return None, ram_formatter, html_formatter, False
return None, ram_formatter, html_formatter, False # type: ignore
if json_logging:
console_formatter = JSONFormatter()

View File

@ -352,9 +352,9 @@ def _chromium_version():
Also see https://www.chromium.org/developers/calendar
and https://chromereleases.googleblog.com/
"""
if webenginesettings is None or QWebEngineProfile is None:
if webenginesettings is None or QWebEngineProfile is None: # type: ignore
# This should never happen
return 'unavailable'
return 'unavailable' # type: ignore
ua = webenginesettings.default_user_agent
if ua is None:
profile = QWebEngineProfile.defaultProfile()