From 68bf155ef0248c48b27d27fce94fdde964788b2a Mon Sep 17 00:00:00 2001 From: Michael Wiencek Date: Fri, 17 Jan 2014 03:58:45 -0600 Subject: [PATCH] Remove type conversion functionality from Options Automatically converting the type is problematic, because if we change the type of an option later (imagine str -> list), it'll pass the old value to the new type constructor before any upgrade hooks are run. With 6ff1f53, there shouldn't be any need to convert the types anyway because sip now does that for us. The 'convert' functionality has been repurposed here for actual format conversions. As it happens, the only Option that needs that is the password field (rot13). --- picard/config.py | 57 +++++++++++------------------------------------- 1 file changed, 13 insertions(+), 44 deletions(-) diff --git a/picard/config.py b/picard/config.py index 4cbaa453b..b41120452 100644 --- a/picard/config.py +++ b/picard/config.py @@ -155,15 +155,16 @@ class Option(QtCore.QObject): registry = {} - def __init__(self, section, name, default, convert=None): + def __init__(self, section, name, default): self.section = section self.name = name self.default = default - self.convert = convert - if not self.convert: - self.convert = type(self.default) self.registry[(self.section, self.name)] = self + @staticmethod + def convert(value): + return value + @classmethod def get(cls, section, name): try: @@ -172,52 +173,20 @@ class Option(QtCore.QObject): raise KeyError("Option %s.%s not found." % (section, name)) -class TextOption(Option): - - """Option with a text value.""" - - def __init__(self, section, name, default): - Option.__init__(self, section, name, default, unicode) - - -class BoolOption(Option): - - """Option with a boolean value.""" - - def __init__(self, section, name, default): - Option.__init__(self, section, name, default, bool) - - -class IntOption(Option): - - """Option with an integer value.""" - - def __init__(self, section, name, default): - Option.__init__(self, section, name, default, int) - - -class FloatOption(Option): - - """Option with a float value.""" - - def __init__(self, section, name, default): - Option.__init__(self, section, name, default, float) - - class PasswordOption(Option): """Super l33t h3ckery!""" - def __init__(self, section, name, default): - Option.__init__(self, section, name, default, rot13) + @staticmethod + def convert(value): + return rot13(value) -class ListOption(Option): - - """Option with a list of values.""" - - def __init__(self, section, name, default): - Option.__init__(self, section, name, default, list) +TextOption = Option +BoolOption = Option +IntOption = Option +FloatOption = Option +ListOption = Option _config = Config()