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:
parent
40d28b80bf
commit
ec053f8007
@ -74,31 +74,27 @@ class TabData:
|
|||||||
"""A simple namespace with a fixed set of attributes.
|
"""A simple namespace with a fixed set of attributes.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
|
_initializing: Set when we're currently in __init__.
|
||||||
keep_icon: Whether the (e.g. cloned) icon should not be cleared on page
|
keep_icon: Whether the (e.g. cloned) icon should not be cleared on page
|
||||||
load.
|
load.
|
||||||
inspector: The QWebInspector used for this webview.
|
inspector: The QWebInspector used for this webview.
|
||||||
|
viewing_source: Set if we're currently showing a source view.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._data = {
|
self._initializing = True
|
||||||
'keep_icon': False,
|
self.keep_icon = False
|
||||||
'viewing_source': False,
|
self.viewing_source = False
|
||||||
'inspector': None,
|
self.inspector = None
|
||||||
}
|
self._initializing = False
|
||||||
|
|
||||||
def __getattr__(self, attr):
|
|
||||||
try:
|
|
||||||
return self._data[attr]
|
|
||||||
except KeyError:
|
|
||||||
raise AttributeError(attr)
|
|
||||||
|
|
||||||
def __setattr__(self, attr, value):
|
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)
|
return super().__setattr__(attr, value)
|
||||||
if attr not in self._data:
|
msg = "Can't set unknown attribute {!r}".format(attr)
|
||||||
msg = "Can't set unknown attribute {!r}".format(attr)
|
raise AttributeError(msg)
|
||||||
raise AttributeError(msg)
|
|
||||||
self._data[attr] = value
|
|
||||||
|
|
||||||
|
|
||||||
class AbstractSearch(QObject):
|
class AbstractSearch(QObject):
|
||||||
|
@ -85,6 +85,7 @@ def whitelist_generator():
|
|||||||
yield 'qutebrowser.utils.log.QtWarningFilter.filter'
|
yield 'qutebrowser.utils.log.QtWarningFilter.filter'
|
||||||
yield 'logging.LogRecord.log_color'
|
yield 'logging.LogRecord.log_color'
|
||||||
yield 'qutebrowser.browser.pdfjs.is_available'
|
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
|
# vulture doesn't notice the hasattr() and thus thinks netrc_used is unused
|
||||||
# in NetworkManager.on_authentication_required
|
# in NetworkManager.on_authentication_required
|
||||||
yield 'PyQt5.QtNetwork.QNetworkReply.netrc_used'
|
yield 'PyQt5.QtNetwork.QNetworkReply.netrc_used'
|
||||||
|
Loading…
Reference in New Issue
Block a user