Use a list as items-argument for usertypes.enum

This commit is contained in:
Florian Bruhin 2014-09-28 00:41:08 +02:00
parent 8636562579
commit 0fadf6b091
16 changed files with 34 additions and 34 deletions

View File

@ -128,8 +128,6 @@ style
- Stuff under scripts/ (especially generate_doc and run_checks) could use a
rewrite.
- Always use a list as argument for namedtuple?
- Refactor enum() so it uses a list as second argument (like python
enum/namedtuple).
- Use separate logger for config
- Use unittest.Mock and especially unittest.patch more.
- Use decorators for on_config_changed

View File

@ -37,9 +37,9 @@ from qutebrowser.utils import usertypes, log, qtutils, message, objreg
ElemTuple = collections.namedtuple('ElemTuple', 'elem, label')
Target = usertypes.enum('Target', 'normal', 'tab', 'tab_bg', 'yank',
'yank_primary', 'fill', 'rapid', 'download',
'userscript', 'spawn')
Target = usertypes.enum('Target', ['normal', 'tab', 'tab_bg', 'yank',
'yank_primary', 'fill', 'rapid', 'download',
'userscript', 'spawn'])
@pyqtSlot(usertypes.KeyMode)

View File

@ -37,8 +37,8 @@ from qutebrowser.config import config
from qutebrowser.utils import log, usertypes, utils
Group = usertypes.enum('Group', 'all', 'links', 'images', 'url', 'prevnext',
'focus')
Group = usertypes.enum('Group', ['all', 'links', 'images', 'url', 'prevnext',
'focus'])
SELECTORS = {

View File

@ -58,7 +58,7 @@ class Command:
AnnotationInfo = collections.namedtuple('AnnotationInfo',
'kwargs, typ, name, flag')
ParamType = usertypes.enum('ParamType', 'flag', 'positional')
ParamType = usertypes.enum('ParamType', ['flag', 'positional'])
def __init__(self, name, split, hide, instance, completion, modes,
not_modes, needs_js, is_debug, ignore_args,

View File

@ -35,7 +35,7 @@ from PyQt5.QtCore import QStandardPaths
from qutebrowser.config import config
from qutebrowser.utils import usertypes, utils
MapType = usertypes.enum('MapType', 'attribute', 'setter', 'static_setter')
MapType = usertypes.enum('MapType', ['attribute', 'setter', 'static_setter'])
MAPPINGS = {

View File

@ -69,9 +69,9 @@ class BaseKeyParser(QObject):
keystring_updated = pyqtSignal(str)
do_log = True
Match = usertypes.enum('Match', 'partial', 'definitive', 'ambiguous',
'none')
Type = usertypes.enum('Type', 'chain', 'special')
Match = usertypes.enum('Match', ['partial', 'definitive', 'ambiguous',
'none'])
Type = usertypes.enum('Type', ['chain', 'special'])
def __init__(self, parent=None, supports_count=None,
supports_chains=False):

View File

@ -32,7 +32,7 @@ from qutebrowser.utils import usertypes, log, objreg, utils
STARTCHARS = ":/?"
LastPress = usertypes.enum('LastPress', 'none', 'filtertext', 'keystring')
LastPress = usertypes.enum('LastPress', ['none', 'filtertext', 'keystring'])
class NormalKeyParser(keyparser.CommandKeyParser):

View File

@ -29,7 +29,8 @@ from PyQt5.QtGui import QStandardItemModel, QStandardItem
from qutebrowser.utils import usertypes, qtutils
Role = usertypes.enum('Role', 'marks', 'sort', start=Qt.UserRole, is_int=True)
Role = usertypes.enum('Role', ['marks', 'sort'], start=Qt.UserRole,
is_int=True)
class BaseCompletionModel(QStandardItemModel):

View File

@ -26,7 +26,7 @@ from qutebrowser.config import config
from qutebrowser.utils import usertypes, qtutils, objreg, utils
Role = usertypes.enum('Role', 'item', start=Qt.UserRole, is_int=True)
Role = usertypes.enum('Role', ['item'], start=Qt.UserRole, is_int=True)
class DownloadModel(QAbstractListModel):

View File

@ -35,7 +35,7 @@ class EnumTests(unittest.TestCase):
"""
def setUp(self):
self.enum = usertypes.enum('Enum', 'one', 'two')
self.enum = usertypes.enum('Enum', ['one', 'two'])
def test_values(self):
"""Test if enum members resolve to the right values."""
@ -54,7 +54,7 @@ class EnumTests(unittest.TestCase):
def test_start(self):
"""Test the start= argument."""
e = usertypes.enum('Enum', 'three', 'four', start=3)
e = usertypes.enum('Enum', ['three', 'four'], start=3)
self.assertEqual(e.three.value, 3)
self.assertEqual(e.four.value, 4)

View File

@ -73,8 +73,8 @@ class DocstringParser:
arg_descs: A dict of argument names to their descriptions
"""
State = usertypes.enum('State', 'short', 'desc', 'desc_hidden',
'arg_start', 'arg_inside', 'misc')
State = usertypes.enum('State', ['short', 'desc', 'desc_hidden',
'arg_start', 'arg_inside', 'misc'])
def __init__(self, func):
"""Constructor.

View File

@ -35,12 +35,12 @@ from qutebrowser.utils import log, qtutils, utils
_UNSET = object()
def enum(name, *items, start=1, is_int=False):
def enum(name, items, start=1, is_int=False):
"""Factory for simple enumerations.
Args:
name: Name of the enum
*items: Items to be sequentally enumerated.
items: Iterable of ttems to be sequentally enumerated.
start: The number to use for the first value.
We use 1 as default so enum members are always True.
is_init: True if the enum should be a Python IntEnum
@ -65,7 +65,7 @@ class NeighborList(collections.abc.Sequence):
_mode: The current mode.
"""
Modes = enum('Modes', 'block', 'wrap', 'exception')
Modes = enum('Modes', ['block', 'wrap', 'exception'])
def __init__(self, items=None, default=_UNSET, mode=Modes.exception):
"""Constructor.
@ -224,21 +224,21 @@ class NeighborList(collections.abc.Sequence):
# The mode of a Question.
PromptMode = enum('PromptMode', 'yesno', 'text', 'user_pwd', 'alert')
PromptMode = enum('PromptMode', ['yesno', 'text', 'user_pwd', 'alert'])
# Where to open a clicked link.
ClickTarget = enum('ClickTarget', 'normal', 'tab', 'tab_bg')
ClickTarget = enum('ClickTarget', ['normal', 'tab', 'tab_bg'])
# Key input modes
KeyMode = enum('KeyMode', 'normal', 'hint', 'command', 'yesno', 'prompt',
'insert', 'passthrough')
KeyMode = enum('KeyMode', ['normal', 'hint', 'command', 'yesno', 'prompt',
'insert', 'passthrough'])
# Available command completions
Completion = enum('Completion', 'command', 'section', 'option', 'value',
'helptopic')
Completion = enum('Completion', ['command', 'section', 'option', 'value',
'helptopic'])
class Question(QObject):

View File

@ -32,7 +32,8 @@ from qutebrowser.widgets.statusbar import (command, progress, keystring,
from qutebrowser.widgets.statusbar import text as textwidget
PreviousWidget = usertypes.enum('PreviousWidget', 'none', 'prompt', 'command')
PreviousWidget = usertypes.enum('PreviousWidget', ['none', 'prompt',
'command'])
class StatusBar(QWidget):

View File

@ -39,7 +39,7 @@ class Text(textbase.TextBase):
available. If not, the permanent text is shown.
"""
Text = usertypes.enum('Text', 'normal', 'temp', 'js')
Text = usertypes.enum('Text', ['normal', 'temp', 'js'])
def __init__(self, parent=None):
super().__init__(parent)

View File

@ -28,8 +28,8 @@ from qutebrowser.utils import usertypes
# Note this has entries for success/error/warn from widgets.webview:LoadStatus
UrlType = usertypes.enum('UrlType', 'success', 'error', 'warn', 'hover',
'normal')
UrlType = usertypes.enum('UrlType', ['success', 'error', 'warn', 'hover',
'normal'])
class UrlText(textbase.TextBase):

View File

@ -33,8 +33,8 @@ from qutebrowser.browser import webpage, hints, webelem
from qutebrowser.commands import cmdexc
LoadStatus = usertypes.enum('LoadStatus', 'none', 'success', 'error', 'warn',
'loading')
LoadStatus = usertypes.enum('LoadStatus', ['none', 'success', 'error', 'warn',
'loading'])
tab_id_gen = itertools.count(0)