Simplify TabData implementation

This uses direct attributes instead of self._data which means we can
only override __setattr__, and pylint will better understand what's
happening.
This commit is contained in:
Florian Bruhin 2016-07-07 09:53:14 +02:00
parent 40d28b80bf
commit ec053f8007
2 changed files with 13 additions and 16 deletions

View File

@ -74,31 +74,27 @@ class TabData:
"""A simple namespace with a fixed set of attributes.
Attributes:
_initializing: Set when we're currently in __init__.
keep_icon: Whether the (e.g. cloned) icon should not be cleared on page
load.
inspector: The QWebInspector used for this webview.
viewing_source: Set if we're currently showing a source view.
"""
def __init__(self):
self._data = {
'keep_icon': False,
'viewing_source': False,
'inspector': None,
}
def __getattr__(self, attr):
try:
return self._data[attr]
except KeyError:
raise AttributeError(attr)
self._initializing = True
self.keep_icon = False
self.viewing_source = False
self.inspector = None
self._initializing = False
def __setattr__(self, attr, value):
if attr.startswith('_'):
if (attr == '_initializing' or
getattr(self, '_initializing', False) or
hasattr(self, attr)):
return super().__setattr__(attr, value)
if attr not in self._data:
msg = "Can't set unknown attribute {!r}".format(attr)
raise AttributeError(msg)
self._data[attr] = value
msg = "Can't set unknown attribute {!r}".format(attr)
raise AttributeError(msg)
class AbstractSearch(QObject):

View File

@ -85,6 +85,7 @@ def whitelist_generator():
yield 'qutebrowser.utils.log.QtWarningFilter.filter'
yield 'logging.LogRecord.log_color'
yield 'qutebrowser.browser.pdfjs.is_available'
yield 'qutebrowser.browser.tab.TabData._initializing'
# vulture doesn't notice the hasattr() and thus thinks netrc_used is unused
# in NetworkManager.on_authentication_required
yield 'PyQt5.QtNetwork.QNetworkReply.netrc_used'