summaryrefslogtreecommitdiff
path: root/qutebrowser/misc/sessions.py
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2018-11-22 15:02:41 +0100
committerFlorian Bruhin <me@the-compiler.org>2018-11-26 18:25:12 +0100
commit12b26512fc511518d3b37d37eb78b406991e08d2 (patch)
treed4fd922203336a0b1e4365329fbff0bafb8edefc /qutebrowser/misc/sessions.py
parent8b1fd83366eeae0a11146bf50291a66362063a3c (diff)
downloadqutebrowser-12b26512fc511518d3b37d37eb78b406991e08d2.tar.gz
qutebrowser-12b26512fc511518d3b37d37eb78b406991e08d2.zip
mypy: Fix :session-save
We use a sentinel value for the argument so we can check whether the default was used. To express that in the type system, it needs a separate class.
Diffstat (limited to 'qutebrowser/misc/sessions.py')
-rw-r--r--qutebrowser/misc/sessions.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/qutebrowser/misc/sessions.py b/qutebrowser/misc/sessions.py
index 78adeb983..9d3736cdb 100644
--- a/qutebrowser/misc/sessions.py
+++ b/qutebrowser/misc/sessions.py
@@ -23,6 +23,7 @@ import os
import os.path
import itertools
import urllib
+import typing
from PyQt5.QtCore import QUrl, QObject, QPoint, QTimer
from PyQt5.QtWidgets import QApplication
@@ -37,7 +38,12 @@ from qutebrowser.mainwindow import mainwindow
from qutebrowser.qt import sip
-default = object() # Sentinel value
+class Sentinel:
+
+ pass
+
+
+default = Sentinel()
def init(parent=None):
@@ -109,7 +115,7 @@ class SessionManager(QObject):
def __init__(self, base_path, parent=None):
super().__init__(parent)
- self._current = None
+ self._current = None # type: typing.Optional[str]
self._base_path = base_path
self._last_window_session = None
self.did_load = False
@@ -504,8 +510,9 @@ class SessionManager(QObject):
@cmdutils.argument('name', completion=miscmodels.session)
@cmdutils.argument('win_id', win_id=True)
@cmdutils.argument('with_private', flag='p')
- def session_save(self, name: str = default, current=False, quiet=False,
- force=False, only_active_window=False, with_private=False,
+ def session_save(self, name: typing.Union[str, Sentinel] = default,
+ current=False, quiet=False, force=False,
+ only_active_window=False, with_private=False,
win_id=None):
"""Save a session.
@@ -518,7 +525,9 @@ class SessionManager(QObject):
only_active_window: Saves only tabs of the currently active window.
with_private: Include private windows.
"""
- if name is not default and name.startswith('_') and not force:
+ if (not isinstance(name, Sentinel) and
+ name.startswith('_') and
+ not force):
raise cmdexc.CommandError("{} is an internal session, use --force "
"to save anyways.".format(name))
if current: